Thursday, November 29, 2007

How To Detect Mobile Devices on Your Site

This is not an easy task if you don't know what kind of headers were sent from various mobile browsers and how to detect them. But this php script on Andy Moore's sites shows you how you can detect them effectively. You can easily modify the script to work on any other language you prefer.

Sunday, November 18, 2007

Powerful Linux Find Command

If you want to find files in a certain directory modified sometime ago, you could use these commands to find out easily:

* Example: find everything in current directory modified in the last 24 hours:
  • find . -mtime 0

* Example: find everything in current directory modified in the last 7 days:
  • find . -mtime -7

* Example: find everything in current directory that have NOT been modified in the last year:
  • find . -mtime -365

* Example: find everything in current directory that had been modified more recently than "abc.txt":
  • find . -newer abc.txt

Monday, August 06, 2007

How Vbulletin Report Post Function Works

Ever wonder what Vbulletin Report Post function does? The message does not go anywhere to the AdminCP or ModCP. Instead it just sends out email to moderators of the respective forum. If no moderator is assigned to the forum, the email is sent to the Administrator of the forum. However, you can change the default behaviour from AdminCP->Vbulletin Options->User Infractions & Post Reporting Options->Post Reporting Email. There are three options to choose, No Email, Post to Moderator, Post to Moderators (default), Super Moderators and Administrators.

Monday, January 29, 2007

Making Your Spring Service Layer Classes Application Context Aware

Spring framework has a nice feature to make your service layer classes applciation context aware. Basically, wiht ApplicationContext you can get messages stored in properties file. For JSP pages this can be easily done with tag libraries. But from the service layer classes, it is quite difficult to get those MessageResourceBundel class and other configuration settings. By implementing ApplicationContextAware from your service layer class, you get a reference to the ApplicationContext object and read in whatever properties you want to read. Below is a code snippet:

public class xxxxController extends FormAction implements ApplicationContextAware{
..................


public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.appContext=applicationContext;
}
}

Once this code has be inserted, you are ready to get the messages in the properties file like this:

String message = appContext.getMessage("your desired message name", new Object[]{param1,param2}, Locale.getDefault());

where param1 and param2 are of any Object type that you want to inject to the message which has the format like this:

Hellow {0}, today is {1}......

Tuesday, January 16, 2007

Web 2.0 logo creator by Alex P (Alternate link)

Thanks to Alex for coming up with this kool piece of tool. It has attracted so many visitors that the main site is not working anymore. Here is the alternate link to generate the images http://h-master.net/web2.0/index.php.

Here's what I have created and the code I used to generate this image.
[c=FF0000]D[/c][c=00C400]O[/c][c=0000FF]R[/c][c=FF0000]I[/c][c=0000AA]S[/c]

Generated Image

Friday, September 15, 2006

Opera 9 browser on Ubuntu Dapper

I was pleased with Opera's offer for easy download and install of its browser for many linux platforms.
The installation was easy. Just double click on the .deb file and the installation will take care of the rest. Opera is famous for its lightweight and fast page loading. I find that it actually loads the web pages faster than any other browser. But there are some incompatibilities with lots of websites on the Internet for Opera browser. Even this blogger site textbox does not auto wrap the text to the next line.

Monday, September 11, 2006

Customizing JCAPTCHA, opensource Java api for CAPTCHA

It took me some time to customize the engine which generate words for CAPTCHA validation. The api has no easy way to change the behaviour of the word generation. After all, I find a way to do it. I extends the class SimpleListImageCaptchaEngine and overwrite buildInitialFactories method to get desired behaviour. Basically what I want is to use UPPERCASE letters and numbers only which are also safe from confusion(for example 0,O,L,I).Here's the code:

import java.awt.Color;

import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
import com.octo.captcha.component.image.backgroundgenerator.FunkyBackgroundGenerator;
import com.octo.captcha.component.image.fontgenerator.FontGenerator;
import com.octo.captcha.component.image.fontgenerator.TwistedAndShearedRandomFontGenerator;
import com.octo.captcha.component.image.textpaster.RandomTextPaster;
import com.octo.captcha.component.image.textpaster.TextPaster;
import com.octo.captcha.engine.image.gimpy.SimpleListImageCaptchaEngine;

public class MyImageCaptchaEngine extends SimpleListImageCaptchaEngine {

public MyImageCaptchaEngine() {
super();
}
protected void buildInitialFactories() {
com.octo.captcha.component.word.wordgenerator.WordGenerator wordGenerator = new com.octo.captcha.component.word.wordgenerator.RandomWordGenerator(
"123456789ABCDEFGHJKMNPQRSTUVWXYZ"); //Use only uppercase letters and safe characters (i.e. omits chars like O,L,I)
TextPaster textPaster = new RandomTextPaster(new Integer(5),
new Integer(8), Color.white);
BackgroundGenerator backgroundGenerator = new FunkyBackgroundGenerator(
new Integer(200), new Integer(100));
FontGenerator fontGenerator = new TwistedAndShearedRandomFontGenerator(
new Integer(25), new Integer(30));
com.octo.captcha.component.image.wordtoimage.WordToImage wordToImage = new com.octo.captcha.component.image.wordtoimage.ComposedWordToImage(
fontGenerator, backgroundGenerator, textPaster);
this.addFactory(
new com.octo.captcha.image.gimpy.GimpyFactory(wordGenerator,
wordToImage));
}
}

Sunday, August 20, 2006

Firefox and Socks Proxy Woes

When it comes to socks proxy configuraiton, Firefox is a weaker contender to IE. For a few hours, I could not figure out why some socks proxies don't work. I have verified that those proxies were working before I set them on Firefox. After searching around, I found out that there is a setting called network.proxy.socks_remote_dns which in my opinion is to request remote socks server to resolve dns on behalf of the client. Unfotunately this setting is not available from the Conneciton Setting GUI. I have to type about:config in the address bar to bring up all the firefox settings and type proxy in the filter. This, in my opinion is serious problem with useability. Why is it not available from GUI settings?

If this setting is set to true which I think is default for better security, some proxies will not work! If you don't know this fact and encounter the problem like me, chances are highly likely that the proxy server does not support dns resolving and it is turned on in Firefox.

And the fact is that you don't even have to choose what version of socks you are using in IE. I don't know why Firefox requires it.