Tuesday, December 23, 2014

Thursday, October 16, 2014

MongoDB: investigations

1. Dot should not be used in key name.

Must read blog:
http://longtermlaziness.wordpress.com/2012/08/24/a-post-you-wish-to-read-before-considering-using-mongodb-for-your-next-app/


Sunday, August 17, 2014

setting time zone on remote machine

1. edit php.ini file
/etc/php5/apache2/php.ini

date.timezone= Asia/Culcutta

sudo dpkg-reconfigure tzdata


Wednesday, August 6, 2014

How to increase open file limit for mysql

he solution is to modify the mysql.conf file that defines the upstart service, it is located at /etc/init/mysql.conf and add the following lines before the pre-start block:
# NB: Upstart scripts do not respect
# /etc/security/limits.conf, so the open-file limits
# settings need to be applied here.
limit nofile 32000 32000

check :
mysql> show global variables like 'open%';

Friday, August 1, 2014

Disable apache2 logging

don't forget to disable other vhost logging

at
etc/apache2/conf.d/other-vhost-access-log

debugging mysql failure

culprit # 1 : disk full

df -h

remove logs

repair databases
mysqlcheck --repair --all-databases -u root -p


individual

use <db>
check table <table>
repair table <table>

remove tmp overflow:

sudo umount overflow


Saturday, July 26, 2014

Monday, July 21, 2014

SOX: sound conversion tool in ubuntu

SOX is very good command line tool.

How to install:
 sudo apt-get install sox
 sudo apt-get install lame
 sudo apt-get install libsox-fmt-mp3

Thursday, May 29, 2014

Rackspace: How to update router routes for old server

go through:

http://www.rackspace.com/knowledge_center/article/updating-servicenet-routes-on-cloud-servers-created-before-june-3-2013

wget http://7c1f6a0506404b3af970-42fdda7fdbf4103081a78c20ac1c54cb.r51.cf1.rackcdn.com/add_2013_cloud_routes_v1.0.4.sh


bash add_2013_cloud_routes_v1.0.4.sh 

bash add_2013_cloud_routes_v1.0.4.sh --check

sudo bash add_2013_cloud_routes_v1.0.4.sh --add-route


Tuesday, May 27, 2014

In app purchase android: signature verification error

Use below tips to resolve it:

If you have used the android.test.purchased then one way to get rid of the error is to do the following:-
  1. Edit Security.java and change the "return false" line in the verifyPurchase to "return true" - this is temporary, we'll be putting it back in a minute.
  2. In your QueryInventoryFinishedListener, after the "if (result.isFailure()) {...}" lines add the following to consume and get rid of your never ending android.test.purchased item:-
    if (inventory.hasPurchase(SKU_ANDROID_TEST_PURCHASE_GOOD)) {
    mHelper.consumeAsync(inventory.getPurchase(SKU_ANDROID_TEST_PURCHASE_GOOD),null); }
  3. Run your app so the consunmeAsync happens, this gets rid of the "android.test.purchased" item on the server.
  4. Remove the consumeAsync code (or comment it out).
  5. Back in the Security.java, change the "return true" back to "return false".

Reference:
http://stackoverflow.com/questions/14600664/android-in-app-purchase-signature-verification-failed

Monday, May 26, 2014

New hire setup at hinkhoj

Tech to Learn:
1. ubuntu operating system
2. apt-get tool for installing new softwares.

Import softwares to be installed:
1. git
2. vim
3.apache2
4.php5
5.mysql-server
6. phpmyadmin


new machine setup:
1. install ubuntu 12.04 LTS x64
3. configure /var/www/ folder

sudo adduser hinkhoj www-data
sudo chown hinkhoj:www-data -R /var/www
sudo chmod 755 -R /var/www


Android setup:
1. get adt complete bundle
2. make link to eclipse on desktop
3. install 32 libs for 12.04 LTS on x64

Bashrc setup:

export PATH=$PATH:$HOME/android-sdk/sdk/platform-tools:$HOME/android-sdk/sdk/tools


Monday, May 19, 2014

PHP: display date with right timezone


$date = new DateTime($row['date_added'], new DateTimeZone('UTC'));
$date->setTimezone("Asia/Culcutta");
            $reportInfo[]=Array(
                               'status'=>$row['status'],
                               'date'=>$date->format("d-m-Y h:i a"),

Wednesday, May 14, 2014

Apache2: How to check status

use : http://localhost/server-status

1. is status module enabled?
/etc/apache2/mods-enabled/status.conf


Open using below command:

lynx http://localhost/server-status




Monday, May 12, 2014

Android: Listview with expandable hieght

Use below code:
package HinKhoj.Dictionary.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;

public class ExpandableHeightListView extends ListView
{

    boolean expanded = false;

    public ExpandableHeightListView(Context context)
    {
        super(context);
    }

    public ExpandableHeightListView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public ExpandableHeightListView(Context context, AttributeSet attrs,
            int defStyle)
    {
        super(context, attrs, defStyle);
    }

    public boolean isExpanded()
    {
        return expanded;
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        // HACK! TAKE THAT ANDROID!
        if (isExpanded())
        {
            // Calculate entire height by providing a very large height hint.
            // View.MEASURED_SIZE_MASK represents the largest height possible.
            int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
                    MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, expandSpec);

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = getMeasuredHeight();
        }
        else
        {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    public void setExpanded(boolean expanded)
    {
        this.expanded = expanded;
    }
}


usage:

SimpleListAdapter adapter = new SimpleListAdapter(getActivity(), R.layout.simple_list_item,defMeaning);

meaning_list.setAdapter(adapter);
meaning_list.setExpanded(true);

Tuesday, May 6, 2014

How to check connected ip address to apache2

Run below command to check connected ip address:

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr >ip.txt

open ip.txt to check list


Sunday, May 4, 2014

How to take right receipt of payment

Below conditions should be met:

1. It should be legal receipt of payment.
2. It should mention date in full.
3. It should have Bill Number
4. It Must have signature of payment receiver.
5. It should have Legal name of business.
6. It should contain your name if possible.

After receipt:
1. scan it to expensify or put scanned on drop box.



Saturday, April 26, 2014

website security: disable apache signature

1. open apache config and set ServerTokens to Prod.
 /etc/apache2/conf.d/security

2. set ServerSignature to Off

3. set expose_php to off in php.ini file.


GIT: How to secure git deployment on website

follow below instructions to secure git folder on website:

a) create .htaccess in .git folder

b) add below lines to it

Order deny,allow
Deny from all

Friday, April 25, 2014

Android: How to get listview item with class object

refer below code:

    public void onItemClick(AdapterView<?> parent, View arg1, int position, long arg3) {
   
     StringIdRowItem entry= (StringIdRowItem) parent.getAdapter().getItem(position);

Friday, April 11, 2014

MySql: How to check status

run below query:

mysqladmin -u root -p status

Know slow queries..

enable below lines in /etc/mysql/my.conf

log-slow-queries
long_query_time = 1

Memcached: How to check status

use below command:

echo stats | nc 127.0.0.1 11211


Wednesday, April 9, 2014

Ubuntu 13.10- webserver setup

few things to install

sudo apt-get install php5-json


Right ownership:

1. add admin user to www-data group
sudo adduser <user> www-data


Give ownership of /var/www to www-data group

sudo chown -R :www-data /var/www

sudo chmod -R 775 /var/www

7=> user all permission
7=> group all permission




Tuesday, April 8, 2014

Android dev on ubuntu 64 bit

Launch eclipse:

UBUNTU_MENUPROXY= /home/bhola/android-sdk/eclipse/eclipse

x386 libraries needed:

sudo apt-get install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386


sudo apt-get install libsdl1.2debian:i386

Fix flickering mouse in ubuntu

Fix: Open system-> Display

2. select "unknown display"

3. Disable it.

Sunday, April 6, 2014

Ubuntu: Light weight Desktop install

Install Lubuntu

sudo apt-get install lubuntu-desktop

it is very fast.

Ubuntu: Important keyboard short-cuts

Terminal: Alt+ Ctr+ T

virtual session to UI switch: Alt+F7

virtual session: Cntr+ Alt+F1




Ubuntu: How to speed it up

1. check "Start Up Preferences"
2. Install BUM  (boot up manager)
3. Move /tmp to RAM

sudo vim /etc/fstab

tmpfs /tmp tmpfs defaults,noexec,nosuid 0 0 

Friday, March 7, 2014

Wednesday, March 5, 2014

Apache2 : How to disable directory listing

open sites-available/default file

change to below:
  <Directory /var/www/>
                Options FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>


restart apache2 

Tuesday, March 4, 2014

How to pay TDS online for professional fees

Follow below steps:
1. Open E-tax payment site:

https://onlineservices.tin.egov-nsdl.com/etaxnew/tdsnontds.jsp


2. select challan number 281

3. select 0021 for LLP firms

4. Provide TAN number

5. Make sure Assessment year is correctly selected.

  What is Assessment year and financial year?
Financial year starts from 1st April and ends on 31st March (wherein there is income pertaining to the whole year or part of the year). Assessment year is the year immediately following the financial year wherein the income of the F.Y. is assessed.

for upto March 31 , 2014 ==> assessment year is 2014-15.

From april 1, 2014=> assessment year is 2015-16

6. select Type of payment as 200 (TDS by Tax Payer).

7. select 94J ==> fees for professional and technical services 

8.  select Retail customer when prompt for paid

9. MOST Important:   Download the acknowledgement and save file with below convention
 TDS_<person name>_year_payment_name.pdf


Monday, March 3, 2014

SQL Injection: How to save from it in OpenCart

Tips:
 Always use $this->db->escape() after reading it from $this->request or $_GET

what is sql injection:

below query can be hacked:
[select * from my_table where var='$var']

if i pass $var=' OR delete from my_table where 1

It will delete all content of my_table.

$this->db->escape ...escape ' field so save from injection. 

Jquery: How to handle select

Below is example of how to use jquery select

$('#tag_item').on('change', function() {
  alert( "I am selected");
});


get selected value text:

$("#tag_select").change(function()
{
         var tag_value=$("#tag_select").val();
         if(tag_value!=-1)
     {
     var tag_name=$("#tag_select option:selected").text();
     add_tag_id(tag_value,tag_name);
     }
}

Friday, February 28, 2014

Opencart: Required PHP extension for opencart

Install below extensions:

apt-get install php5-gd
apt-get install php5-curl
apt-get install php5-mcrypt

Thursday, February 27, 2014

SEO Checklist for making page public

Below checklist must be met before making any page public for website:

1. Title:
   It should be short. Use "-" to join keyword pairs. Title is read by customer in google search result so it must be very readable.

 Example:  Learn english - Online english mock tests - Brand Name

2. Description:
  It should be summary of page. Must contain keyword describing the page. It should be in proper language and not stuffed by keywords. It must contain at least 3 sentences or aleast 100 words.

3. canonical tag:
  It show what is primary url for content. It is must for all pages which are public

4. Follow and Index meta tags
   If you don't want page in google result then it must contain meta tag for "NO Index".

5. Keyword exercise: [Most Important]
  write down 5 keywords which are most relevant to page content. These keywords must be present in text of page multiple time.
 use below tool to find keyword relevant to  your page.

  http://internetmarketingengine.com/analyzer/analyzer-lite.php

   Golden questions to ask your self?
    Q1: should customer come on this page searching for above relevant keyword.
    Q2: Is URL of this page contain <most essence summary> and most important keyword to attract customer.


Other Tools:

http://www.wordtracker.com/

http://www.google.co.in/trends/


Rule of Thumb:

Never make a page public without knowing what were right keywords to describe this page.
   

6. URL
 It is most important. Always use .htaccess and UrlBuilder class to build good url.

7. Social Media engagement
  Page must have ways to share page content in social media and ways to get user comments. Facebook comment box is must for each page.

8. ID to indentify page. If a page is auto generated based on data then it must be based on ID.  Always pass ID alone URL to social media as title keep on changing due to modification.

9. 301 Redirect to latest canonical URL. If URL change , it should be 301 redirected to latest URL.

10. Authentic content indicator. use Google plus publisher id in header.

11. Pagination:
  use pagination meta tags as next or prev.

12. Use Responsive design using bootstrap. Each page must be responsive and Fluid and built using Bootstrap.



SEO Tips: How to handle paginated pages

Infinite scroll page is made “search-friendly” when converted to a paginated series -- each component page has a similar <title> with rel=next/prev values declared in the <head>.

Refer to: http://googlewebmastercentral.blogspot.in/2014/02/infinite-scroll-search-friendly.html


Thursday, February 20, 2014

Postfix setup on Ubuntu for GMail

Below steps worked 100% for me:

vim /etc/postfix/main.cf
add below to above:

relayhost = [smtp.gmail.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_tls_CAfile = /etc/postfix/cacert.pem smtp_use_tls = yes


vim /etc/postfix/sasl_passwd

[smtp.gmail.com]:587 USERNAME@gmail.com:PASSWORD

sudo chmod 400 /etc/postfix/sasl_passwd sudo postmap /etc/postfix/sasl_passwd

cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem

sudo /etc/init.d/postfix reload

source: https://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/

Monday, February 10, 2014

Ubuntu 12.10: How to fix evolution-calendar factory related crash

Run below query:

sudo apt-get --reinstall install evolution-data-server indicator-datetime unity-scope-gdocs



Sunday, February 9, 2014

PHP: How to check if key exists in array

php manual:

array_key_exists

(PHP 4 >= 4.0.7, PHP 5)
array_key_exists — Checks if the given key or index exists in the array

Description ¶

bool array_key_exists ( mixed $key , array $array )
array_key_exists() returns TRUE if the given key is set in the array. key can be any value possible for an array index.


GIT: How to git push to remote repo

You can update remote git using below method:

step 1: add remote git
 $git remote add <remote-git-nick-name> <remote git address>

ex: git remote  add rgit brmeena@remotegit.com:/var/remotegit/.git

step 2: git push rgit master


Note: run below command on remote server:
  git config receive.denyCurrentBranch ignore


Saturday, February 8, 2014

Ordering Mysql items multiple time in a query

Hint: below php statement

$query="select * from question_category_info where q_parent_category_id='$parent_id' ORDER BY priority DESC, q_category_name ASC";
       


Wednesday, February 5, 2014

android: customize text color using spannable string

use below hint:

SpannableString deleteStr = new SpannableString("Delete Question");
deleteStr.setSpan(new ForegroundColorSpan(Color.BLACK), 0, deleteStr.length(), 0);
menu.add(2, 2, 2, deleteStr);

Thursday, January 30, 2014

Saturday, January 25, 2014

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:
  • 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'
You will then see a TXT record in two parts, one piece has the domain and the other has the actual TXT record. You need to go into your DNS settings on your server for your domain and add this record. If your DNS control panel does not allow you to add the domain of google._domainkey, simply make the domain fully qualified like google._domainkey.onlinetyari.com

Debugging 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.

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;
    }

}

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 &

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

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:
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:
$ for i in /*; do echo $i; find $i | wc -l; done
Then 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;   
}

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



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">&nbsp;</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">&nbsp;</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">&nbsp;</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>

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


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

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


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'));
      
       }

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


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; ?>

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!"
                }
            }
        });

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-scrollbars

Restart your machine after it.