Wednesday, July 18, 2012

how to create git branch

To see the existing list of branches on the local machine, run the below command:

git branch

To create a new branch, use this:
git checkout -b new_branch

This is a shorthand for:
git branch new_branch
git checkout new_branch

To delete a branch from local machine:
git branch -D new_branch

See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Tuesday, July 17, 2012

Get the list of cookies in iOS phonegap

To get the list of cookies stored into our iPhone, we use below code block:

NSArray *cookieArray;
cookieArray = [cookieStorage cookies];
NSInteger numcookies = [cookieArray count]; 
NSLog(@"cookies count:%d", numcookies); 

for (NSHTTPCookie *each in [cookieStorage cookies]) {
    NSLog(@"\nCOOKIE Name: %@, Value:%@, Expires At: %@\n", [each name], [each value], [each expiresDate]); 
    }


Cookies are stored into the NSHTTPCookieStorage. From that storage, we get each one using NSHTTPCookie object. each object has name, value and expireDate attributes.


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Monday, July 16, 2012

Password protected directory

We work with test and staging server. But we don't want others to access the website. We can stop access for unauthorized users by using passwd feature. First, we create a user/password pair with the passwd command.

htpasswd -c /home/pwww/.htpasswd jerry


Then we create a .htaccess file on the same level where our directory is located that we want to be protected. We placed the below code block in the file:

AuthUserFile /home/pwww/.htpasswd
AuthGroupFile /dev/null
AuthName EnterPassword
AuthType Basic
require user jerry


Then try to reload your directory access using browser. You will get a window asking for authentication.


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Thursday, July 12, 2012

iptables configuration

We can set several different configuration values for the iptables.
To flush the current rules we run the below command:
sudo /sbin/iptables -F

To accept a certain port, run the below:
sudo /sbin/iptables -A INPUT -i eth0 -p tcp -m tcp --dport 30000 -j ACCEPT

To accept certain state, run the below:
sudo /sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

We rejected all incoming and forwarded requests:
sudo /sbin/iptables -A INPUT -j REJECT
sudo /sbin/iptables -A FORWARD -j REJECT

Now accept all outgoing and selected incoming request:
sudo /sbin/iptables -A OUTPUT -j ACCEPT
sudo /sbin/iptables -I INPUT -i lo -j ACCEPT

Reject all incoming loop requests
sudo /sbin/iptables -I INPUT ! -i lo -d 127.0.0.0/8 -j REJECT

It displays the existing rules with line numbers
sudo /sbin/iptables -L --line-numbers

We accept HTTP and HTTPS requests.
sudo /sbin/iptables -I INPUT 3 -p icmp -m icmp --icmp-type 8 -j ACCEPT
sudo /sbin/iptables -I INPUT 5 -p tcp --dport 80 -j ACCEPT 
sudo /sbin/iptables -I INPUT 5 -p tcp --dport 443 -j ACCEPT

We enable the logging features of iptables.
sudo /sbin/iptables -I INPUT 8 -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
To save an existing rules table, use the below commands:
sudo sh -c '/sbin/iptables-save > /etc/iptables.save'


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

How to install fail2ban

We can install fail2ban quite easily in ubuntu. Just install it from aptitude.
sudo apt-get install fail2ban

We make a local copy for the configuration file.
 
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

In the configuration file, we can change several different options as per our need. Like below:
enabled = true
port    = ssh
filter  = sshd
logpath  = /var/log/auth.log
maxretry = 5

We enable the fail2ban for a specific section by setting enable to true. After changing the configuration, we restart fail2ban.
sudo /etc/init.d/fail2ban restart

See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

How to Change Git user

If you want to change the git user credentials in a machine, Then following the below steps.
First, go to the .ssh folder under your user directory.
cd ~/.ssh

We create a folder to backup your existing keys.
mkdir key_backup

And then copy those keys to the backup folder.
cp id_rsa* key_backup

And delete the old keys
rm id_rsa*

Now we create the new keys for our email address.
ssh-keygen -t rsa -C "your_email@youremail.com"

See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

How to install sqlitebrowser

To view sqlite data, we can use the sqlitebrowser from aptitude. The installation command is pretty simple, same as other plugin installation. Just run the following command:
sudo apt-get install sqlitebrowser


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Error with Frontaccounting branch creation

I was trying to create sales report for a customer with the frontaccounting software. But I was facing the following error with the system:
The selected customer and branch are not valid, or the customer does not have any branches.

After googleing the problem, I found that I need to set the default_location value to DEF in the cust_branch table.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

How to detect keyboard close in iPhone phonegap

When we tap into any textbox or textarea in iPhone, it triggers the built-in keyboard in iPhone. We need to detect the close of this keyboard event. The 'blur' event on textbox and textarea detects the close of the keyboard.
The following code detects the keyboard close event and rearrange the page layout by scrolling to top left corner.
$("input[type=text], textarea").bind("blur", function(e) {
    window.scrollTo(0.0);
    loaded();
  });

See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

difference between index, primary, full text, unique in phpmyadmin

In phpmyadmin, we can set attribute for a field with following properties :
  • 1. Index
  • 2. Primary
  • 3. Full Text
  • 4. Unique

Then what is the difference between index, primary, full text,unique in phpmyadmin.
Index: this create a non-unique columns.
primary: there will be one primary key for a table.
fulltext: this is used for full text searching. but others are used for b-treee(selecting, sorting, ranges from left most column) or hash table.
unique: this will be unique throughout the columns

See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Error: Select query cannot join with another table

I was joining two tables in Zend framework. I come across following error:
Error:  Select query cannot join with another table

The code that I was using is as below:
$calc = $this->select()
  ->from(array('c'=>'sed_cal'),array('c.id','c.name'))
  ->join(array('ctr'=>'sed_calc_to_road'),'c.id = ctr.calc_id')
  ->where('ctr.road_id',$id)
  ->order(array('c.id ASC'));

After searching the web, I found that I need to use the setIntegrityCheck function with false value. Hence, the code goes as this:
$calc = $this->select()
  ->setIntegrityCheck(false)
  ->from(array('c'=>'sed_cal'),array('c.id','c.name'))
  ->join(array('ctr'=>'sed_calc_to_road'),'c.id = ctr.calc_id')
  ->where('ctr.road_id',$id)
  ->order(array('c.id ASC'));

See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80no listening sockets available, shutting down

I was trying to run apache, but it was not running and it was displaying the following error message.
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80no listening sockets available, shutting down

It was showing that some other process is using port 80. So, I run the below command to kill the process:
sudo fuser -k -n tcp 80

See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

Problem with successive ajax call & resolve it?

I was working on a mobile application using phonegap recently. I was making calls to the API to fetch data. I found that before completing a request call, another request was made. So, there were some deadlock of request calls.

Hence, we need to remove the request calls that are not used any longer. We need to detect whether the request is completed or not.


The below is the code block to stop ajax request calls. The $.ajax request returns an object. We check this object, whether any request call is running or not. If one request call is there, then we terminate it using the abort function.

var req = null;

function sendRequest (text)
{
        // Check for pending request & cancel it
        if (req) req.abort ();

        req = $.ajax ({
                // various options..
                success: function (data)
                {
                        // Process data
                        ...
                        // reset request
                        req = null;
                }
        });
}

See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

jQuery selector for not starting with

Recently, I want to trace the anchor tags that doesn't start with a hash tag(#). There is a function in jquery named 'not'. and also using the selector modifier '^' to detect the start of the attribute.

Hence, the syntax will be as following:
$('a:not([href^=#])')

See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide