Finding Location of site visitor

May 26th, 2011 prakash No comments

There are few approaches to find the location of the visitor with their IP. I’ll show you some of the approaches that I know :

  • With including a javascript : This is very useful and trust-worthy method, I’ve seen so far. And is really easy to implement.
    Just Include a file

    wherever you want to display. See below how it displays the result :

    Powered by IP Address Locator

    If you are good at javascript or their libraries, you can change it how you wanted to change.
    Original Source by
    www.ipaddresslocation.org

  • Another method is by using service like :
    http://www.hostip.info/use.html
    Call this URL with REST Method and get the result :

    'http://api.hostip.info/get_html.php?ip='
    

    I, personally don’t recommend to use it, because it has very poor output. May be below 60% accuracy.
    See the result below, how accurately this method is showing your location:


  • For Database approach see the link http://www.maxmind.com/app/geoip_country. You can get Many sites which will provide the database with codes package.

jQuery1.5 Cheat Sheet

April 4th, 2011 prakash No comments

jQuery Cheat Sheet for version 1.5, use it for quick reference on learning jquery.
Launch PDF file.

logical NOT NOT operator (!!) ?

March 24th, 2011 prakash No comments

The logical NOT operator can also be used to convert a value into its Boolean equivalent. By using two NOT operators in a row, you can effectively simulate the behavior of the Boolean() casting function.
The first NOT returns a Boolean value no matter what operand it is given. The second NOT negates that Boolean value and so gives the true Boolean value of a variable. The end result is the same as using the Boolean() function on a value.
An Example:
alert(!0); //true
alert(!!0); //false
alert(!NaN); //true
alert(!!NaN); //false

Categories: Uncategorized Tags: ,

arguments.callee – javascript useful property

March 23rd, 2011 prakash No comments

The arguments object is an array like object that contains all of the arguments that were passed into the function. Though its primary use is to represent function arguments, the arguments object also has a property named callee , which is a pointer to the function that owns the arguments object. Consider the

following classic factorial function done with arguments.callee property:


function factorial(num){
     if (num < = 1) {
          return 1;
     } else {
          return num * arguments.callee(num-1)
     }
}

There is no longer a reference to the name “ factorial ” in the function body, which ensures that the recursive call will happen on the correct function no matter how the function is referenced.

Finding n-th level of sibling on DOM with jquery

March 20th, 2011 prakash No comments

By clicking on an element in DOM, to get the which indexed number of the sibling, you’ll need to use jquery’s .index() method which is easy and useful too.
Let’s give an example,
HTML :

 <ul>
     <li>first</li>
     <li>second</li>
     <li>third</li>
 </ul>

Javascript:

$('li').click(function () {
    alert($(this).index());
});

Enjoy jquery

Categories: Uncategorized Tags: ,

CSS and javascript hack for Safari Browser

March 16th, 2011 prakash No comments

Since the Safari and chrome browser uses same webkit, differentiating safari and google chrome browser will be a difficult part. Finally I’ve found out the solution for it,
CSS HACK: for both chrome and safari browser,

@media screen and (-webkit-min-device-pixel-ratio:0){
    #yourdiv{
        margin-left:0;
    }
} 

Javascript Hack : for both chrome and safari browser,

if(window.devicePixelRatio) {
   alert('This is safari or chrome browser');
}

Javascript Hack : for safari and only safari browser,

if (navigator.userAgent.match(/AppleWebKit/) && ! navigator.userAgent.match(/Chrome/)) {
   alert('this is safari brower and only safari brower')
}

Forced Download – PHP

February 14th, 2011 prakash No comments

Use this code :

  1. $file = 'index.php';
  2. if (file_exists($file)) {
  3.  header('Content-Description: File Transfer');
  4.  header('Content-Type: application/octet-stream');
  5.  header('Content-Disposition: attachment; filename='.basename($file));
  6.  header('Content-Transfer-Encoding: binary');
  7.  header('Expires: 0');
  8.  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  9.  header('Pragma: public');
  10.  header('Content-Length: ' . filesize($file));
  11.  ob_clean();
  12.  flush();
  13.  readfile($file);
  14.  exit;
  15. }
Categories: Uncategorized Tags: ,

What is metaprogramming?

February 10th, 2011 prakash No comments

It’s writing code to write code. It’s dynamic code generation. It’s the move from imperative to declarative. It’s a rejection of Java’s endless repetition of boilerplate code. It’s the living embodiment of DRY. Here’s an example:


class Monkey
def name
@name
end
def name= n
@name = n
end
end
Categories: Uncategorized Tags:

Implementing Jquery in Joomla

February 5th, 2011 prakash No comments

Joomla Uses Mootools as it’s javascript library by default, so we’ll need to use the jquery’s power of flexibility ie, jquery noConflict. Below are the examples how to use it.

In admin :

  1. $document =JFactory::getDocument();
  2. $document->addScript('location_to_jquery/jquery-min.js');
  3. $scripts = "jQuery.noConflict()";
  4. $document->addScriptDeclaration($scripts);

In Site :

from template :

  1. <script type="text/javascript" src="<?php echo $this->baseurl ;?>/templates/<?php echo $this->template?>/js/jquery-min.js">
  2. jQuery.noConflict();
  3. </script >
  4. // insert this code inside the <head> tag before <jdoc:include type="head" > tag

From module and component:

  1. $document = JFactory::getDocument();
  2. $document->addScript('location_to_jquery/jquery-min.js');
  3. $scripts = "jQuery.noConflict()";
  4. $document->addScriptDeclaration($scripts);