http://www.vogella.com/tutorials/AndroidActionBar/article.html
Thursday, January 30, 2014
A good tutorial for ActionBar Learning
http://www.vogella.com/tutorials/AndroidActionBar/article.html
Saturday, January 25, 2014
interesting Text to speech engines
Javascript : MeSpeak.js {speak.js }
Java: FreeTTS
Indic languages: Dhvni TTS
Java: FreeTTS
Indic languages: Dhvni TTS
Tuesday, January 14, 2014
Postfix : lessons learnt
How to check mail queue:
mailq
How to delete all mails in queue:
postsuper -d ALL
where to see mail logs:
/var/log/mail.log
How to enable google to authenticate email address:
mailq
How to delete all mails in queue:
postsuper -d ALL
where to see mail logs:
/var/log/mail.log
How to enable google to authenticate email address:
- Go to the Admin Console
- Click on "Google Apps"
- Click on "Gmail"
- Scroll down until you see "Authenticate Email" and click that
- Select the domain you wish to add DKIM to
- When it asks what prefix you want to use, simply use the default of 'google'
google._domainkey, simply make the domain fully qualified like google._domainkey.onlinetyari.comDebugging Jquery validate: Tips
I found below issue why it didn't work:
1. syntax wrong use web developer-> error console
2. Message not provided for rule.
1. syntax wrong use web developer-> error console
2. Message not provided for rule.
Jquery validate: call manually and validate select options
You can validate only one element at a time.
to call manually: sample code
$("#add_new_word").validate().element("#new_eng_word");
$("#add_new_word").validate().element("#new_eng_grammar");
How to validate select option:
keep first option as value=""
select class="form-control" name="new_eng_grammar" id="new_eng_grammar" requied autofocus>
<option value="">Select English Grammar</option>
<?php foreach($englishGrammarTypes as $englishGrammarType)
{
echo "<option value='".$englishGrammarType['value']."'>".$englishGrammarType['name']."</option>";
}
?>
</select>
rules:
new_eng_grammar: {
required: true
},
messages: {
new_eng_grammar: {
required: "Please select english grammar"
}
}
Using it with custom submit button:
function validate()
{
$("#add_new_word").validate().element("#new_hindi_word");
$("#add_new_word").validate().element("#new_eng_word");
$("#add_new_word").validate().element("#new_eng_example");
$("#add_new_word").validate().element("#new_hindi_example");
$("#add_new_word").validate().element("#new_eng_grammar");
$("#add_new_word").validate().element("#new_hindi_grammar");
$("#add_new_word").validate();
}
function addword()
{
validate();
if(!$("#add_new_word").valid())
{
return;
}
}
to call manually: sample code
$("#add_new_word").validate().element("#new_eng_word");
$("#add_new_word").validate().element("#new_eng_grammar");
How to validate select option:
keep first option as value=""
select class="form-control" name="new_eng_grammar" id="new_eng_grammar" requied autofocus>
<option value="">Select English Grammar</option>
<?php foreach($englishGrammarTypes as $englishGrammarType)
{
echo "<option value='".$englishGrammarType['value']."'>".$englishGrammarType['name']."</option>";
}
?>
</select>
rules:
new_eng_grammar: {
required: true
},
messages: {
new_eng_grammar: {
required: "Please select english grammar"
}
}
Using it with custom submit button:
function validate()
{
$("#add_new_word").validate().element("#new_hindi_word");
$("#add_new_word").validate().element("#new_eng_word");
$("#add_new_word").validate().element("#new_eng_example");
$("#add_new_word").validate().element("#new_hindi_example");
$("#add_new_word").validate().element("#new_eng_grammar");
$("#add_new_word").validate().element("#new_hindi_grammar");
$("#add_new_word").validate();
}
function addword()
{
validate();
if(!$("#add_new_word").valid())
{
return;
}
}
Monday, January 13, 2014
Ubuntu: How to enable mod rewrite
step 1:
sudo a2enmod rewrite
sudo vi /etc/apache2/sites-available/default
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
sudo service apache2 restart
Thursday, January 9, 2014
fastest way to remove files in linux
Deleting files through perl is fastest. perl -e 'for(<*>){((stat)[9]<(unlink))}' How to run Linux command in background
Put & after command
example:
find /var/lib/php5 -mtime +2 -name 'sess_*' -delete &
example:
find /var/lib/php5 -mtime +2 -name 'sess_*' -delete &
Must setup for new web server
(i). PHP session clearance cron job
bash script with content:
#!/bin/bash
find /var/lib/php5 -mtime +2 -name 'sess_*' -delete
Add to cron job
1. crontab -e
2.
# m h dom mon dow command
5 0 * * * cleansession.sh
3. service cron restart
(ii) Enable Mod rewrite and Headers
refer to blog post:
http://bholameena.blogspot.in/2014/01/ubuntu-how-to-enable-mod-rewrite.html
(iii) Enable Headers
$ sudo a2enmod headers
bash script with content:
#!/bin/bash
find /var/lib/php5 -mtime +2 -name 'sess_*' -delete
Add to cron job
1. crontab -e
2.
# m h dom mon dow command
5 0 * * * cleansession.sh
3. service cron restart
(ii) Enable Mod rewrite and Headers
refer to blog post:
http://bholameena.blogspot.in/2014/01/ubuntu-how-to-enable-mod-rewrite.html
(iii) Enable Headers
$ sudo a2enmod headers
Useful Linux commands
Finds all files with extentions:
sudo find /var/log/ -mtime +2 -name '*.log'
Delete all files with extention:
sudo find /var/log/ -mtime +2 -name '*.log' -delete
Recursive number of files:
sudo find /var/log/ -mtime +2 -name '*.log'
Delete all files with extention:
sudo find /var/log/ -mtime +2 -name '*.log' -delete
Recursive number of files:
for i in /var/*; do echo $i; find $i | wc -l; done
How to check disk files issues: inode exceeded
Check inode through:
df -i
To count all the files in a directory and all it's subdirectories:
df -i
To count all the files in a directory and all it's subdirectories:
$ for i in /*; do echo $i; find $i | wc -l; doneThen you can narrow down your search by replacing the
/* for any directory that has an unusually large number of files in. For me it was /var$ for i in /var/*; do echo $i; find $i | wc -l; done
Delete when rm fails:
find . -mtime +2 -name '*' -delete
Website Maintenance: Importance of HTTP 503
Include below code for maintenance of site:
define('OT_MAINTENANCE',false);
if(OT_MAINTENANCE)
{
header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Status: 503 Service unavailable");
header("Retry-After: 3600");
echo '<h2>Service not available. Site under Maintenance. Please try later.</h2>';
exit;
}
define('OT_MAINTENANCE',false);
if(OT_MAINTENANCE)
{
header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Status: 503 Service unavailable");
header("Retry-After: 3600");
echo '<h2>Service not available. Site under Maintenance. Please try later.</h2>';
exit;
}
Mysql emergency: How to backup data of crashed mysql
$ cd path/to/mount/var/lib/
$ sudo tar -czvf mysql.tgz mysql/
Once you’ve gzipped your data, scp it over to your new server.$ scp mysql.tgz user@newserverip:
How to Fix Mysql start issue
Problem:InnoDB: Compressed tables use zlib 1.2.3.4 mysqld: Can't create/write to file '/tmp/ibfIRdc9' (Errcode: 28)
solution:
1. delete files in /tmp. Make sure disk has free space.
2. restart mysql
solution:
1. delete files in /tmp. Make sure disk has free space.
2. restart mysql
Wednesday, January 8, 2014
Sample code: How to insert table items using jquery
Below is sample code to auto insert table items using jquery.
$('#word_info_detail tbody').remove(); //clean all rows.
insert items:
html = '<tbody id="roundtrip_price_' + price_data_key + '">';
html += '<tr>';
html += '<td class="left" style="width:3px;">';
html += '<span onclick="removeRoundtripPrice(' + data.price_detail['car_type_id']+','+data.price_detail['ac_type']+');" class="remove"> </span>';
html += '</td>';
html += '<td class="left" style="width:3px;">';
html += '<span id="active_rt_price_'+price_data_key+'" onclick="inactivateRoundtripPrice(' + data.price_detail['car_type_id']+','+data.price_detail['ac_type']+');" class="active"> </span>';
html += '<span style="display:none" id="inactive_rt_price_'+price_data_key+'" onclick="activateRoundtripPrice(' + data.price_detail['car_type_id']+','+data.price_detail['ac_type']+');" class="inactive"> </span>';
html += '</td>';
html += '<td class="left">' + data.price_detail['car_model'] + '</td>';
html += '<td class="right">Rs. ' + data.price_detail['fare'] + ' / km</td>';
html += '<td class="right">Rs. ' + data.price_detail['driver_charge_per_day'] + ' / day</td>';
html += '<td class="right">' + data.price_detail['min_km_per_day'] + ' Km / day</td>';
html += '</tr>';
html += '</tbody>';
$('#roundtrip_price_list').append(html);
$('#word_info_detail tbody').remove(); //clean all rows.
insert items:
html = '<tbody id="roundtrip_price_' + price_data_key + '">';
html += '<tr>';
html += '<td class="left" style="width:3px;">';
html += '<span onclick="removeRoundtripPrice(' + data.price_detail['car_type_id']+','+data.price_detail['ac_type']+');" class="remove"> </span>';
html += '</td>';
html += '<td class="left" style="width:3px;">';
html += '<span id="active_rt_price_'+price_data_key+'" onclick="inactivateRoundtripPrice(' + data.price_detail['car_type_id']+','+data.price_detail['ac_type']+');" class="active"> </span>';
html += '<span style="display:none" id="inactive_rt_price_'+price_data_key+'" onclick="activateRoundtripPrice(' + data.price_detail['car_type_id']+','+data.price_detail['ac_type']+');" class="inactive"> </span>';
html += '</td>';
html += '<td class="left">' + data.price_detail['car_model'] + '</td>';
html += '<td class="right">Rs. ' + data.price_detail['fare'] + ' / km</td>';
html += '<td class="right">Rs. ' + data.price_detail['driver_charge_per_day'] + ' / day</td>';
html += '<td class="right">' + data.price_detail['min_km_per_day'] + ' Km / day</td>';
html += '</tr>';
html += '</tbody>';
$('#roundtrip_price_list').append(html);
How to import common ResourceDictionary in windows 8 project
Step 1: open App.xaml
Step 2:
<Application
x:Class="HinkhojDictApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HinkhojDictApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--
Styles that define common aspects of the platform look and feel
Required by Visual Studio project and item templates
-->
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
<ResourceDictionary Source="HinkhojStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Step 2:
<Application
x:Class="HinkhojDictApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HinkhojDictApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--
Styles that define common aspects of the platform look and feel
Required by Visual Studio project and item templates
-->
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
<ResourceDictionary Source="HinkhojStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Tuesday, January 7, 2014
How to exclude files from git
Step 1: Git remove files
$ git rm --cached *.sqlite
Step 2: Create .gitignore file
$vi .gitignore
write line ==> *.sqlite
$ git rm --cached *.sqlite
Step 2: Create .gitignore file
$vi .gitignore
write line ==> *.sqlite
How to Git push in bare empty repository
if you see below message:
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
You need to push using below commands:
$ git push origin master
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
You need to push using below commands:
$ git push origin master
Monday, January 6, 2014
How to debug apache website errors
You can view apache logging at below location in Ubuntu:
1. cd /var/log/apache2
2. tail -30 error.log
1. cd /var/log/apache2
2. tail -30 error.log
How to use: Remote method for Jquery form validation
I recently done work related to Async automatic Remote validation of Form elements.
Pr-requisite: Download Jquery validation Plugin from http://jqueryvalidation.org/
Step 1: define form HTML
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label>User Name:</label></div>
<div class="col-md-4"><input type="text" name="user_id" id="user_id"
class="form-control"
placeholder="User Id" required autofocus /></div>
</div>
Step 2:
define Form validation:
$("#form").validate({
rules: {
user_id: {
required:true,
minlength:5,
remote: {
url: 'ajax/dup_user_id_checker.php'
}
}
Step 3:
Define remote method which return "true" for success and "error messages" for failure.
source: ajax/dup_user_id_checker.php
public function dup_user_id_check()
{
$output=Array();
if(!isset($this->request->get['user_id']))
{
$output="Unable to check for duplicate user name";
}
else
{
$user_id=$this->request->get['user_id'];
$this->load->model('user/user');
if($this->model_user_user->IsUserExists($user_id))
{
$output="$user_id already taken.";
}
else
{
$this->log->write($user_id." found");
$output="true";
}
}
$this->data['json_output']=json_encode($output);
$this->template = 'common/json.tpl';
$this->children = array();
$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
}
Pr-requisite: Download Jquery validation Plugin from http://jqueryvalidation.org/
Step 1: define form HTML
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label>User Name:</label></div>
<div class="col-md-4"><input type="text" name="user_id" id="user_id"
class="form-control"
placeholder="User Id" required autofocus /></div>
</div>
Step 2:
define Form validation:
$("#form").validate({
rules: {
user_id: {
required:true,
minlength:5,
remote: {
url: 'ajax/dup_user_id_checker.php'
}
}
Step 3:
Define remote method which return "true" for success and "error messages" for failure.
source: ajax/dup_user_id_checker.php
public function dup_user_id_check()
{
$output=Array();
if(!isset($this->request->get['user_id']))
{
$output="Unable to check for duplicate user name";
}
else
{
$user_id=$this->request->get['user_id'];
$this->load->model('user/user');
if($this->model_user_user->IsUserExists($user_id))
{
$output="$user_id already taken.";
}
else
{
$this->log->write($user_id." found");
$output="true";
}
}
$this->data['json_output']=json_encode($output);
$this->template = 'common/json.tpl';
$this->children = array();
$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
}
Sunday, January 5, 2014
Ubuntu: How to setup Memcached for Php
Use below commands to setup Memcached for Php
1. sudo apt-get install memcached
2. sudo apt-get install php5-memecached
3. sudo service apache2 restart
1. sudo apt-get install memcached
2. sudo apt-get install php5-memecached
3. sudo service apache2 restart
Twitter Bootstrap: Sample code using it
Twitter Bootstrap is recommended CSS for basic HTML UI controls.
Below is sample code I used :
<?php echo $header; ?>
<div class="row">
<div class="col-md-9">
<h2 class="form-signin-heading" style="text-align:left;margin:20px">Please Register for Contributor account</h2><?php if ($error_warning) { ?>
<div class="warning" style="padding: 3px;"><?php echo $error_warning; ?></div>
<?php } ?>
<form role="form" action="<?php echo $action; ?>" method="post"
enctype="multipart/form-data" id="form">
<div class="row">
<div class="col-md-3"><label>First Name</label></div>
<div class="col-md-4"><input type="text" name="first_name"
class="form-control"
placeholder="First Name" required autofocus /></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label>Last Name</label></div>
<div class="col-md-4"><input type="text" name="last_name"
class="form-control"
placeholder="Last Name" required autofocus /></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label>User Id</label></div>
<div class="col-md-4"><input type="text" name="user_id"
class="form-control"
placeholder="User Id" required autofocus /></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label>E-Mail Address:</label></div>
<div class="col-md-4"><input type="text" name="email"
class="form-control"
placeholder="E-mail address" required autofocus /></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label> Password:</label></div>
<div class="col-md-4"><input type="password" name="password"
value="<?php echo $password; ?>" class="form-control"
placeholder="Password" required/></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label> Re-enter Password</label></div>
<div class="col-md-4"><input type="password2" name="password2"
value="<?php echo $password; ?>" class="form-control"
placeholder="Re-enter Password" required/></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3">
<button onclick="$('#form').submit(); return false;" href="#"
class="btn btn-lg btn-primary btn-block" type="submit">Register</button>
</div>
</div>
<?php if ($redirect) { ?> <input type="hidden" name="redirect"
value="<?php echo $redirect; ?>" /> <?php } ?>
</form>
</div>
</div>
<script type="text/javascript"><!--
$('#form input').keydown(function(e) {
if (e.keyCode == 13) {
$('#form').submit();
}
});
//-->
$("#form").validate({
rules: {
email: {
required: true,
email: true,
remote: {
url: "<?php echo HTTP_SERVER."ajax/dup_user_id_check.php";?>",
type: "post"
}
}
},
messages: {
email: {
required: "Please Enter Email!",
email: "This is not a valid email!",
remote: "Email already in use!"
}
}
});
</script>
<?php echo $footer; ?>
Below is sample code I used :
<?php echo $header; ?>
<div class="row">
<div class="col-md-9">
<h2 class="form-signin-heading" style="text-align:left;margin:20px">Please Register for Contributor account</h2><?php if ($error_warning) { ?>
<div class="warning" style="padding: 3px;"><?php echo $error_warning; ?></div>
<?php } ?>
<form role="form" action="<?php echo $action; ?>" method="post"
enctype="multipart/form-data" id="form">
<div class="row">
<div class="col-md-3"><label>First Name</label></div>
<div class="col-md-4"><input type="text" name="first_name"
class="form-control"
placeholder="First Name" required autofocus /></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label>Last Name</label></div>
<div class="col-md-4"><input type="text" name="last_name"
class="form-control"
placeholder="Last Name" required autofocus /></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label>User Id</label></div>
<div class="col-md-4"><input type="text" name="user_id"
class="form-control"
placeholder="User Id" required autofocus /></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label>E-Mail Address:</label></div>
<div class="col-md-4"><input type="text" name="email"
class="form-control"
placeholder="E-mail address" required autofocus /></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label> Password:</label></div>
<div class="col-md-4"><input type="password" name="password"
value="<?php echo $password; ?>" class="form-control"
placeholder="Password" required/></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3"><label> Re-enter Password</label></div>
<div class="col-md-4"><input type="password2" name="password2"
value="<?php echo $password; ?>" class="form-control"
placeholder="Re-enter Password" required/></div>
</div>
<div class="row" style="margin-top:10px">
<div class="col-md-3">
<button onclick="$('#form').submit(); return false;" href="#"
class="btn btn-lg btn-primary btn-block" type="submit">Register</button>
</div>
</div>
<?php if ($redirect) { ?> <input type="hidden" name="redirect"
value="<?php echo $redirect; ?>" /> <?php } ?>
</form>
</div>
</div>
<script type="text/javascript"><!--
$('#form input').keydown(function(e) {
if (e.keyCode == 13) {
$('#form').submit();
}
});
//-->
$("#form").validate({
rules: {
email: {
required: true,
email: true,
remote: {
url: "<?php echo HTTP_SERVER."ajax/dup_user_id_check.php";?>",
type: "post"
}
}
},
messages: {
email: {
required: "Please Enter Email!",
email: "This is not a valid email!",
remote: "Email already in use!"
}
}
});
</script>
<?php echo $footer; ?>
Best Practices : HTML Forms validation
Use Jquiry based validation plugin.
download from :
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
CDN:
http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js
Sample code used by me:
$("#form").validate({
rules: {
email: {
required: true,
email: true,
remote: {
url: "<?php echo HTTP_SERVER."ajax/dup_user_id_check.php";?>",
type: "post"
}
}
},
messages: {
email: {
required: "Please Enter Email!",
email: "This is not a valid email!",
remote: "Email already in use!"
}
}
});
download from :
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
CDN:
http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js
Sample code used by me:
$("#form").validate({
rules: {
email: {
required: true,
email: true,
remote: {
url: "<?php echo HTTP_SERVER."ajax/dup_user_id_check.php";?>",
type: "post"
}
}
},
messages: {
email: {
required: "Please Enter Email!",
email: "This is not a valid email!",
remote: "Email already in use!"
}
}
});
Friday, January 3, 2014
How to disable to overlay scollbar in Ubuntu
Run below command: echo export LIBOVERLAY_SCROLLBAR=0 | sudo tee -a /etc/X11/Xsession.d/99disable-overlay-scrollbarsRestart your machine after it.
Subscribe to:
Comments (Atom)