Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Sunday, December 6, 2009

Google Analytics new asynchronous tracking code

Google Analytics has now provides new asynchronous tracking code. The main feature of the asynchronous code is that it could load ga.js while the page is being rendered.

There are two ways to use this code.

  1. Place the code below before the  </head> tag.
     <script type="text/javascript">  
     var _gaq = _gaq || [];  
     _gaq.push(['_setAccount', 'UA-XXXXX-X']);  
     _gaq.push(['_trackPageview']);  
     (function() {  
       var ga = document.createElement('script');  
       ga.src = ('https:' == document.location.protocol  
         ? 'https://ssl' : 'http://www')  
         + '.google-analytics.com/ga.js';  
       ga.setAttribute('async', 'true');  
       document.documentElement.firstChild.appendChild(ga);  
     })();  
     </script>  
    

  2. Split the code. Half of the code will be put before the </head> tag. Another half will be put at the end of the page, before the </body> tag.
    The first half (before </head> the tag).
     <script type="text/javascript">  
     var _gaq = _gaq || [];  
     _gaq.push(['_setAccount', 'UA-XXXXX-X']);  
     _gaq.push(['_trackPageview']);  
     </script>  
    
    The second half (before </body> the tag).
     <script type="text/javascript">  
     (function() {  
       var ga = document.createElement('script');  
       ga.src = ('https:' == document.location.protocol  
         ? 'https://ssl' : 'http://www')  
         + '.google-analytics.com/ga.js';  
       ga.setAttribute('async', 'true');  
       document.documentElement.firstChild.appendChild(ga);  
     })();  
     </script>  
    

Note:

  1. Remove any existing Google Analytics code before using this asynchronous code.

  2. Disable any Google Analytics plugin (if you use one) for WordPress.

  3. Replace UA-XXXXX-X with your web property ID.

Monday, June 22, 2009

How to create a secure, memorable PIN number

Usually people will use their existing numbers, such as telephone number, house number, birth date or social security number as their PIN number for banking. These numbers are easy to remember, nevertheless easy to be broken.

This article will give an idea on how to create a secure, but memorable PIN number.

How to create the PIN number


The technique is so simple. You need to create your own simple algorithm to generate the PIN number, based on the number that you already memorized. In case you forget the PIN number, it can always be generate easily using the algorithm.

An example of algorithm


Let say you want to generate a PIN that consists of six digits.

  1. First create the secret number. Think of a 3 digits number that you won’t forget. For example, if you are born in 1965, you can use 965 as the secret number.

  2. Use your algorithm to create the PIN number.
    Example: Add the secret number in step 1 with the number one, and multiply it back to itself.
    965 * (965 +  1) = 932190

  3. Therefore, your PIN number is 932190.

Different PIN number for different bank


Using this technique, you will have a PIN number that cannot easily be guessed by others. But, what if you want different PIN number for different bank?

You can also create different PIN number for different bank, using the same algorithm and secret number.

Just associate bank1 with 1, bank2 with 2, and bank3 with 3. Then, you can replace the number one in your algorithm with two for bank2 and three for bank3.

Conclusion


This article shows on how to create PIN numbers from one secret number and an algorithm. Using this technique you will only need to remember the secret number, the algorithm and the bank association number.

Wednesday, April 16, 2008

How to embed source code in a blog

code

To embed source code inside blogger blog, like in the picture above, I use a css box like below:

.code {
font-family: ‘Courier New’, Courier, monospace;
white-space: pre;
line-height: 1.4em;
margin: 1em 0;
border: 1px dashed #aaa8a8;
padding: 0.5em 0 0.3em 0.5em;
font-size: 100%;
color: #000;
overflow: auto;
max-width: 100%;
/*max-height: 400px;*/
}


To use it just call the class named ’code’ using div.
<div class="code"> The source code goes here! </div>

The tab will be preserved. In order to limit the height of the box, remove the comment (”/*” and “*/”) from the last line, and set the desired height.
/* max-height: 400px; */

For some reason, in IE, the text will be wrapped instead of displaying the scroll bar. However, it works just fine inside Firefox and Opera. If you have suggestion on how to solve this problem, don’t hesitate to leave a comment.