Saturday, October 20

Facebook and AD Campaigns



Is it true, bots are clicking on the ads in facebook?

Yes, its True!

Limited Run Company noticed it could only verify about 20 percent of the clicks that were supposedly being converted to users showing up on its Web site.

80% of clicks it was paying for were coming from bots.

Bots are computer scripts or fake users who simply repeatedly click the ads.
  

What if you complain this to facebook?

If a complaint is send to Facebook, then it demands for the below information:
  1. Server Logs
  2. Aggregated counts of your clicks

What are these?

1. Server Logs

Raw server logs of all clicks coming to your website, or the total amount of all clicks coming from Facebook, with an explanation of how you filtered them.

These server logs must contain:
  1. Timestamp of page load
  2. User agent string
  3. User IP
  4. Exact page loaded, with the parameters passed

 2. Aggregated counts of your clicks (Optional)

If possible, please also include the following:
  1. The total number of clicks you received from Facebook split by day, for the specific time period where you have noticed the click issues.
  2. The total number of clicks you were billed for, by Facebook, also by billable day for the period in question.
  3. A screenshot of your external reporting system showing the total number of clicks received from Facebook.


How to get Server Logs?

For Tomcat Application Server, it can be achieved by setting the value of ‘Access Log Valve’ tag, in pattern attribute as ‘combined’ in server.xml.

<Valve className="org.apache.catalina.valves.AccessLogValve" pattern="combined" directory="logs" prefix="yoursitename_access" suffix=".txt" />
  

Techniques to find or block bots


1. Unique Cookie is one way to find out whether a user has registered multiple times from the campaign or not.

When a user registers from a campaign, server should store a unique cookie value to that user’s browser. So the next time a user registers from that browser, server can find out by looking at the cookie stored.


2. Create a blacklist of user agents of known bots like FeedBurner, Googlebot.

Whenever a request comes, compare their user agent string with the blacklist, to determine whether these are bots or not. Or even a prevention step can also be taken from these identified bots.

This implementation has a performance hit because we have to check each user request user agent to the blacklist.

Also some user agents are real users (hired by ad agency for cheap labour). No blacklist is going to have those real users.


3. Flag bot vs. non-bot.

Log information about browsers which cannot execute Javascript, and then built some sort of system that analyzes these browsers and their trends (like, if they originate from a certain IP range).
 Javascript is something that is on by default and for a user to turn it off is an explicit manual action. No user wants to turn off the javascript, unless for doing any suspicious activity or he is a guy who hates the word ‘java’.

But this means cannot catch the bots until after the analysis.

4.  Whenever user registers, send a verification code to the user’s email or sms to authenticate the identity.
 

5.  Captcha
captcha block bot technique

           But not good for user experience and may even prevent irritated users from registering.  


References:

Saturday, September 1

Year 2038 Bug



Year 2038 Bug


Computer programs, softwares and systems that uses 32 bit integer to represent UNIX Time will fail after 19th, Jan, 2038 at 3:14:07.

What ?

Unix Time is another way of telling time, mostly for computer’s understanding. Each instances are defined as number of seconds elapsed after 1970-01-01 00:00:00.

Eg: UNIX Time for 31st Aug 2012 18:59:09 = 1346439549


On 19th, Jan, 2038 at 3:14:07, the 32 bit signed integer will reach its limit. After that, bit will overflow the 32-bit counter and reset the time to 1st Jan, 1901.

2038 bug


Attention to Mysql Users


Mysql 5 is a 32 bit database, it has a function UNIX_TIMESTAMP() which returns seconds since 1970-01-01 00:00:00. This function will return only 0 after 19th Jan, 2038 03:14:07 GMT.


The end time would be different for each region based on their time zone.

Auckland +12:00 19-01-2038 15:14:07
Sydney +10:00 19-01-2038 13:14:07
Tokyo +9:00 19-01-2038 12:14:07
Beijing +8:00 19-01-2038 11:14:07
Mumbai +5:30 19-01-2038 08:44:07
Dubai +4:00 19-01-2038 07:14:07
Nairobi +3:00 19-01-2038 06:14:07
Cairo +2:00 19-01-2038 05:14:07
Paris +1:00 19-01-2038 04:14:07
London UTC 19-01-2038 03:14:07
Brasilia -3:00 19-01-2038 00:14:07
Atlantic Time -4:00 18-01-2038 23:14:07
Eastern Time -5:00 18-01-2038 22:14:07
Central Time -6:00 18-01-2038 21:14:07
Mountain Time -7:00 18-01-2038 20:14:07
Pacific Time -8:00 18-01-2038 19:14:07
Hawai -10:00 18-01-2038 17:14:07

References:

1. http://en.wikipedia.org/wiki/Year_2038_problem
2. http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_unix-timestamp

Friday, July 27

Google search Tips



 1.      filetype:  For searching for a specific file type only.

E.g.:  Search for ppt files           
           
computer networks filetype:ppt


2.      cache:  This is to load sites quickly.

E.g.:
           
cache:http://www.thehindu.com


3.      movie:  It shows all information regarding the movie.

E.g.:
           
movie:Dark Knight


4.      site:  To search within a site domain

E.g.:
           
entrance result site:gov.in


5.      phonebook:  To get details of a person using phone number

E.g.:
           
phonebook:28576300


6.      “ ”    For searching for an exact phrase

E.g.:
           
how to change tyre


7.        -   To exclude a particular word in the search

E.g.:  To exclude all search relating to cricket match

cricket -game -score

Thursday, July 5

Fix Memory Leak in Java


Fix Memory Leak in Java

Actions to prevent memory leak:

  1. When a reference variable is no longer in use, assign null value to it.
  2. Close DataInputStreams and JDBC Connections.
  3. Shutdown the threads after completion.
  4. Restrict using static classes and methods.
  5. Put less data on Sessions.
  6. Invalidate Sessions.
  7. Set short duration for timeout of sessions.
  8. Avoid using String for concatenation instead use StringBuffer.

How do we know memory leak is happening?

Getting OutOfMemoryError (OOM) is a sign of possible memory leak. The other way is by checking the used JVM heap size. If the heap size is rising with time then clearly you have memory leak.

memory leak java heapdump graph


Debugging memory leak

  • In Tomcat, open Catalina.bat file, set CATALINA_OPTS with XX:+HeapDumpOnOutOfMemoryError
set CATALINA_OPTS=%CATALINA_OPTS% -XX:+HeapDumpOnOutOfMemoryError


  • Now a heap dump is written on the first Out Of Memory Error into %CATALINA_HOME%\bin as java_pid<pid>.hprof
memory leak java heapdump file


  • Or for On-demand, if you are using Java6, then use jmap.exe -dump:format=b,file=HeapDump.hprof  <pid>  
memory leak java jmap




Wednesday, June 27

How to Increase your Laptop Battery Life


Batteries live longer if treated in a gentle manner. The longevity is often a direct result of the environmental stresses applied.

Following are the steps to increase your notebook’s battery life:
  1. Do not ever let your Battery Power fall below 40%.
  2. Do not ever charge at or below 0o C.
  3. Always best to work with Power supply Plugged-in.
  4. Always best to give a 30 min break after 3 hour usage. Shutdown or hibernate the notebook and plug-off the Power supply.
  5. Make sure to leave your battery power between 50% - 40%, if you are not going to use the notebook for long time (like more than 6 hours)
notebook battery power should not decrease 40%


Why not to let Battery Power fall below 40% ?
Do not discharge lithium-ion too deeply. Instead, charge it frequently. Lithium-ion does not have memory problems like nickel-cadmium batteries. No deep discharges are needed for conditioning. Deep discharges will increase the temperature and reduce battery life. If Li-ion cells are discharged below a certain voltage a chemical reaction occurs that make them dangerous if recharged, which is why probably all such batteries in consumer goods now have an "electronic fuse" that permanently disables them if the voltage falls below a set level. The electronic fuse draws a small amount of current from the battery, which means that if a notebook battery is left for a long time without charging it, and with a low initial state of charge, the battery may be permanently destroyed.

Why not charge at or below 0o C ?
Do not charge lithium-ion at or below freezing temperature. Although accepting charge, an irreversible plating of metallic lithium will occur that compromises the safety of the pack.

Why is it best to work with Power supply Plugged-in ?
Plugged-in power supply takes control of the power requirements and stress is relieved from battery. Also less battery discharges occurs.

Why to give a 30 min break after 3 hour usage ?
A continuous usage gives more stress on the battery and raises the battery temperature and thereby reducing life. A frequent break can allow to battery to cool down to a nominal temperature and prevents increase of temperature to critical levels. Degradation of battery occurs faster at higher temperatures. Degradation in lithium-ion batteries is caused by an increased internal battery resistance due to cell oxidation. This decreases the efficiency of the battery, resulting in less net current available to be drawn from the battery.

Why need to keep battery power at 50%-40% before long time non usage of notebook?
When storing, lithium batteries degrade more while fully charged than if they are only 40% charged.



References
http://batteryuniversity.com/learn/article/the_high_power_lithium_ion/

Monday, June 4

How to set Google as default search engine in Internet Explorer

Microsoft has made it really difficult for people using ie8 or ie9 in setting Google as their default search engine.
Follow these simple steps:
  1. Open your Internet Explorer.
  2. Go to this link  http://www.iegallery.com/en-US/Addons/Details/813
  3. Click on "Add to Internet Explorer".
  4. Check the ''Make this my default search provider" option.
  5. Click on "Add" button.
Now Google is set as  default search engine.


Add Google Add-on to Internet Explorer




Make this my default search provider

+ UPDATE on 30-07-2012

Some have complained that they are still not able to see Google search Addon. 

Please access this link http://www.google.com/homepage/search/ and click on "Switch Now!" .

set google as default search



 For More Add-ons in IE, please refer to this link http://www.iegallery.com/Addons .

Monday, December 12

How to make your computer fast

Well it doesn’t matter that you use Pentium 4 (1.2GHz) Processor.

You still can make your system reasonably fast.


Please note:

This article is for Windows XP.

It’s best to perform in the stage order.

The more deeper you go more small sacrifices you make for the only goal “Performance”, “Performance” and  “Performance”.



Following are the stages below:























Stage 1 : Uninstall unwanted softwares

1.      Open Control Panel -> Add or Remove Programs  

2.      Remove software that are not being used, by clicking Remove buttons



3.       Follow the ‘Next’ button, until the software is successfully uninstalled.



Stage 2 : Free more space in C Drive

1.      Delete unwanted files, only the ones you created, in C drive.

2.      Move all the files, only the ones you created, to some other drives.

Note: Don’t touch any system files or Windows folder or Program Files folder

3.       Whenever installing a program next time onwards, keep the destination folder as d:\Program Files\



Stage 3 : Cleanup the Disk


1.      Right-click on C Drive -> Properties



 


  2.      Click on “Disk Cleanup” button, and then wait for some time till it scans the drive.
 
3.      Mark Tick in all the checkbox to safely delete all unnecessary files, and then click ‘Ok’ button.




 

 


Stage 4 : Increase Virtual Memory

1.      Right-click on ‘My Computer’ -> Properties

2.      Select ‘Advanced’ tab -> Click ‘Settings’ under Performance Section.




 

3.      In ‘Performance Options’ Wizard -> ‘Advanced’ tab
4.      In ‘Virtual Memory’ section -> click on ‘Change’ button.







5.      In ‘Virtual Memory’, select C: drive
6.      Select ‘Custom Size’
7.      Enter Initial size (MB): 2046
8.      Enter Maximum size (MB): 3000 or 4092
9.      Click on ‘Set’ button and then on ‘Ok’ button.



 




Stage 5 : Scan and Clean for Viruses

1.      Full scan your computer using the antivirus.
2.      Delete the entire virus found.


Stage 6 : Disk Defragmenter

1.      Right-click on ‘My Computer’ -> Manage




 


2.      In right menu ‘Computer Management(Local)’ -> ‘Storage’ -> ‘Disk Defragmenter’

3.      Select one drive by drive

4.      Click on the ‘Defragment’ button, it may take some time to defragment the drive.



 






Stage 7 : Remove all applications load at start-up (except the really needed ones)

1.      Start -> Run
2.      Type msconfig and then click ‘Ok’ button.


3.      In ‘System Configuration Utility’ -> ‘Startup’ tab
4.      Unmark the tick on the checkbox of the applications that you installed and don’t use as the system starts.

Reason: When your system starts, all the softwares are sharing the memory at the startup till shutdown, even though it’s not used. So its better remove the applications to load at startup to increase the boot-time and system speed.

5.       Click ‘Ok’ and then ‘Restart’ button




 





Stage 8 : Set your system for “Performance” mode rather appearance.


1.      Right-click on ‘My Computer’ -> Properties

2.      Select ‘Advanced’ tab -> Click ‘Settings’ under Performance Section.



 
 

3.      In ‘Performance Options’ Wizard -> ‘Visual Effects’ tab

4.      Select  “Adjust for best performance” option and then click ‘Ok’ button.

 



Stage 9 : Upgrade your RAM to  minimum 2GB or more.

1.      Upgrade your system physical memory to minimum 2 GB or more.
2.      Check the FSB speed and type of your RAM, it can be found out using a software ‘CPU-Z’.
3.      Download ‘CPU-Z’.
4.      Buy a RAM that matches your FSB and DDR version.


Sunday, October 23

Aspect Oriented Programming ( AOP )


Why is AOP required?
We use Object-Oriented Programming (OOP), Functional-Oriented Programming (FOP) models basically to solve Concerns.

- Concerns like reusability of code in case of FOP.
- Concerns like data access, data integrity, data stability in case of OOP.

Even though we use many techniques in OOP to group and encapsulate the concerns into separate, independent entities by providing abstractions. But some concerns still defy these forms of implementation, and are called crosscutting concerns because they "cut across" multiple abstractions in a program.

Example: Logging

Logging is a crosscutting concern, because a logging strategy necessarily affects every logged part of the system. Logging thereby crosscuts all logged classes and methods.


Now Logging aspect is scattered or tangled as code, making it harder to understand and maintain. It is scattered by virtue of the function being spread over a number of unrelated functions that might use it, possibly in entirely unrelated systems, different source languages, etc. 


To change logging means the effect will be cascading to all the classes where logging is implemented. It would be a huge task to modify the places where the logging is called.



Simple Banking Scenario Example – Transfer money to another account
 
void transfer(Account fromAcc, Account toAcc, int amount , Logger logger)
throws Exception 
{
  logger.info("transferring money...");
 
  if (fromAcc.getBalance() < amount) 
  {
    logger.info("Insufficient Funds, sorry");
    throw new InsufficientFundsException();
  }
  fromAcc.withdraw(amount);
  toAcc.deposit(amount);
  logger.info("Successful transaction.");
 
}



Now consider what happens if we suddenly need to change the logging considerations for the application. In the program's current version, logging-related operations appear scattered across numerous methods, and such a change would require a major effort.



AOP’s Rescue Solution

AOP attempts to solve this problem by defining rules :


  1. To find the places where you need to change the code, and
  2. To suggest what new requirements or functionality you need to add.

These rules are called Aspects.

So now a class or jar file is created, loaded or at runtime, the new functionality that you declared is automatically inserted. The extent of the new implementation is how you have defined the aspect rules.



Example:


In the above logging example, I need to add the time when the logging was created.


@Aspect
public class LoggingAspect {
    @Before("call(void Logger.info(String)) && within(*)")
    public void findtime() {
        Logger.out.print(new java.util.Date());
    }
}

So here we have set the :

1st rule is to find the function [Logger.info()] to be modified.

2nd rule is to specify within which all packages [within(*)] the implementation should be done.

3rd rule is to specify what new functionality is to be replaced with [findtime()].

4th rule is to specify whether the new functionality is to be inserted before or after the code [@Before]. 

Now create a following XML config file in META-INF folder on the classpath.



<aspects>

    <aspect name="LoggingAspect"/>

</aspects>


Benefits

Now after each class is loaded in the server, if it pass the aspect conditions then the new functionality will be automatically inserted.

We can create a central place to change the cross cutting concerns. A change in one place is affected in all code.

Deployment in production server is easy as it requires no modification of production code and no or less downtime.