Godaddy Discount coupon codes

Some coupon codes that give some discounts when you buy domains. I checked all of them myself just now. If you see any invalid/wrong code, let me know.

.com domains 30% off: gdr0802v
.com domains 30% off (new and renewals): gdr0802aq
new .coms 30% off: gb99 
.com 30% off: gdr0802wb 20%off: gdr0809ap

BTW, you can also buy cheap domains from our friends at HostMe

Firefox Download Counter for websites

It is fun to see how the Firefox initiative is growing. Years back, I had done a small hack which will bring the download counter status from the SpreadFirefox website.

I just checked that code again today. Surprisingly, it still works.

Want the code? Here it is.

PHP Code:
<code><code>/* * admin [at] pchelp.in Display number of FireFox downloads graphically. * */// It is a png image - not HTML
header("Content-type: image/png");
$buf = file("http://feeds.spreadfirefox.com/downloads/firefox.xml?ff=1");

//Whats in between?
$replace = Array("<description>","</description>");
$my_count = trim(str_replace($replace,'',$buf[9]));

//Put this font in the same directory. I am using Arial-Rounded
$font = "ARLRDBD.TTF";

//Base image. Get it from http://pchelp.in/images/misc/3.png
//and use it to create the image.
$im = imagecreatefrompng('images/misc/3.png');

//Change to any color you want.
$grey = imagecolorallocate($im, 66,66,66);
imagettftext($im, 10, 0, 44, 22, $grey, $font,$my_count." Downloads");
imagepng($im);
imagedestroy($im);

You can use your own font and base image. Let me know how you are using this 

[J2ME] SSL connections to http/mail servers using Java

I want to connect to mail(pop/imap) and/or HTTP servers over secure sockets layer. I am seeing multiple options to do so. Anybody ventured into this? Whats the best way to do this in a J2me mobile app? Any low level explanation will be helpful.

Some options
1) https
2) javax.microedition.io.secureconnection

 

j2me secure socket connection code: Here is a solution from the Corej2ME book (thanks to @daaku for the lead). Although this is not a complete code, this can pretty much be the starting point of a https based connection in J2ME

[code]

<span style="color: #3f7f5f;">/*--------------------------------------------------</span>
<span style="color: #3f7f5f;">* ViewFile.java</span>
<span style="color: #3f7f5f;">*</span>
<span style="color: #3f7f5f;">* Send client request (method, header, body)</span>
<span style="color: #3f7f5f;">* Get server response (status, header, body)</span>
<span style="color: #3f7f5f;">*</span>
<span style="color: #3f7f5f;">* Example from the book: Core J2ME Technology</span>
<span style="color: #3f7f5f;">* Copyright John W. Muchow <a href="http://www.corej2me.com/" target="_blank">http://www.CoreJ2ME.com</a></span>
<span style="color: #3f7f5f;">* You may use/modify for any non-commercial purpose</span>
<span style="color: #3f7f5f;">*-------------------------------------------------*/</span>
<span style="color: #7f0055;">import </span><span style="color: #000000;">javax.microedition.midlet.*;</span>
<span style="color: #7f0055;">import </span><span style="color: #000000;">javax.microedition.io.*;</span>
<span style="color: #7f0055;">import </span><span style="color: #000000;">java.io.*;</span>

<span style="color: #7f0055;">public class </span><span style="color: #000000;">ViewFile </span><span style="color: #7f0055;">extends </span><span style="color: #000000;">MIDlet</span>
<span style="color: #000000;">{</span>
<span style="color: #7f0055;">private </span><span style="color: #000000;">String url = </span><span style="color: #2a00ff;">"http://www.corej2me.com/midpbook_v1e1/ch14/getHeaderInfo.txt"</span><span style="color: #000000;">;</span>

<span style="color: #7f0055;">public </span><span style="color: #7f0055;">void </span><span style="color: #000000;">startApp</span><span style="color: #000000;">()</span>
<span style="color: #000000;">{</span>
<span style="color: #7f0055;">try</span>
<span style="color: #000000;">{</span>
<span style="color: #000000;">processRequest</span><span style="color: #000000;">()</span><span style="color: #000000;">;</span>
<span style="color: #000000;">}</span>
<span style="color: #7f0055;">catch </span><span style="color: #000000;">(</span><span style="color: #000000;">Exception e</span><span style="color: #000000;">)</span>
<span style="color: #000000;">{</span>
<span style="color: #000000;">System.err.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"Msg: " </span><span style="color: #000000;">+ e.toString</span><span style="color: #000000;">())</span><span style="color: #000000;">;</span>
<span style="color: #000000;">}</span>
<span style="color: #000000;">} </span>

<span style="color: #7f0055;">private </span><span style="color: #7f0055;">void </span><span style="color: #000000;">processRequest</span><span style="color: #000000;">() </span><span style="color: #7f0055;">throws </span><span style="color: #000000;">IOException</span>
<span style="color: #000000;">{</span>
<span style="color: #000000;">HttpConnection http = </span><span style="color: #7f0055;">null</span><span style="color: #000000;">;</span>
<span style="color: #000000;">InputStream iStrm = </span><span style="color: #7f0055;">null</span><span style="color: #000000;">;</span>

<span style="color: #7f0055;">try</span>
<span style="color: #000000;">{</span>
<span style="color: #3f7f5f;">// Create the connection</span>
<span style="color: #000000;">http = </span><span style="color: #000000;">(</span><span style="color: #000000;">HttpConnection</span><span style="color: #000000;">) </span><span style="color: #000000;">Connector.open</span><span style="color: #000000;">(</span><span style="color: #000000;">url</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span>

<span style="color: #3f7f5f;">//----------------</span>
<span style="color: #3f7f5f;">// Client Request</span>
<span style="color: #3f7f5f;">//----------------</span>
<span style="color: #3f7f5f;">// 1) Send request method</span>
<span style="color: #000000;">http.setRequestMethod</span><span style="color: #000000;">(</span><span style="color: #000000;">HttpConnection.GET</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span>

<span style="color: #3f7f5f;">// 2) Send header information (this header is optional)</span>
<span style="color: #000000;">http.setRequestProperty</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"User-Agent"</span><span style="color: #000000;">, </span><span style="color: #2a00ff;">"Profile/MIDP-1.0 Configuration/CLDC-1.0"</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span>
<span style="color: #3f7f5f;">// http.setRequestProperty("If-Modified-Since", "Mon, 16 Jul 2001 22:54:26 GMT");</span>

<span style="color: #3f7f5f;">// If you experience IO problems, try </span>
<span style="color: #3f7f5f;">// removing the comment from the following line</span>
<span style="color: #3f7f5f;">//http.setRequestProperty("Connection", "close"); </span>

<span style="color: #3f7f5f;">// 3) Send body/data - No data for this request</span>

[/code]

 

Server code

[code]

<span style="color: #3f7f5f;">// Server Response</span>
<span style="color: #3f7f5f;">//----------------</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"url: " </span><span style="color: #000000;">+ url</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"-------------------------"</span><span style="color: #000000;">)</span><span style="color: #000000;">; </span>

<span style="color: #3f7f5f;">// 1) Get status Line</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"Msg: " </span><span style="color: #000000;">+ http.getResponseMessage</span><span style="color: #000000;">())</span><span style="color: #000000;">; </span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"Code: " </span><span style="color: #000000;">+ http.getResponseCode</span><span style="color: #000000;">())</span><span style="color: #000000;">; </span>

<span style="color: #3f7f5f;">// 2) Get header information </span>
<span style="color: #7f0055;">if </span><span style="color: #000000;">(</span><span style="color: #000000;">http.getResponseCode</span><span style="color: #000000;">() </span><span style="color: #000000;">== HttpConnection.HTTP_OK</span><span style="color: #000000;">)</span>
<span style="color: #000000;">{</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"field 0: " </span><span style="color: #000000;">+ http.getHeaderField</span><span style="color: #000000;">(</span><span style="color: #990000;">0</span><span style="color: #000000;">))</span><span style="color: #000000;">; </span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"field 1: " </span><span style="color: #000000;">+ http.getHeaderField</span><span style="color: #000000;">(</span><span style="color: #990000;">1</span><span style="color: #000000;">))</span><span style="color: #000000;">;</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"field 2: " </span><span style="color: #000000;">+ http.getHeaderField</span><span style="color: #000000;">(</span><span style="color: #990000;">2</span><span style="color: #000000;">))</span><span style="color: #000000;">; </span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"-------------------------"</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"key 0: " </span><span style="color: #000000;">+ http.getHeaderFieldKey</span><span style="color: #000000;">(</span><span style="color: #990000;">0</span><span style="color: #000000;">))</span><span style="color: #000000;">; </span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"key 1 : " </span><span style="color: #000000;">+ http.getHeaderFieldKey</span><span style="color: #000000;">(</span><span style="color: #990000;">1</span><span style="color: #000000;">))</span><span style="color: #000000;">; </span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"key 2: " </span><span style="color: #000000;">+ http.getHeaderFieldKey</span><span style="color: #000000;">(</span><span style="color: #990000;">2</span><span style="color: #000000;">))</span><span style="color: #000000;">; </span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"-------------------------"</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"content: " </span><span style="color: #000000;">+ http.getHeaderField</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"content-type"</span><span style="color: #000000;">))</span><span style="color: #000000;">;</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"date: " </span><span style="color: #000000;">+ http.getHeaderField</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"date"</span><span style="color: #000000;">))</span><span style="color: #000000;">;</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"last-modified: " </span><span style="color: #000000;">+ http.getHeaderField</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"last-modified"</span><span style="color: #000000;">))</span><span style="color: #000000;">; </span>

<span style="color: #3f7f5f;">// 3) Get data (show the file contents)</span>
<span style="color: #000000;">String str;</span>
<span style="color: #000000;">iStrm = http.openInputStream</span><span style="color: #000000;">()</span><span style="color: #000000;">;</span>
<span style="color: #7f0055;">int </span><span style="color: #000000;">length = </span><span style="color: #000000;">(</span><span style="color: #7f0055;">int</span><span style="color: #000000;">) </span><span style="color: #000000;">http.getLength</span><span style="color: #000000;">()</span><span style="color: #000000;">;</span>
<span style="color: #7f0055;">if </span><span style="color: #000000;">(</span><span style="color: #000000;">length != -</span><span style="color: #990000;">1</span><span style="color: #000000;">)</span>
<span style="color: #000000;">{</span>
<span style="color: #3f7f5f;">// Read data in one chunk</span>
<span style="color: #7f0055;">byte </span><span style="color: #000000;">serverData</span><span style="color: #000000;">[] </span><span style="color: #000000;">= </span><span style="color: #7f0055;">new </span><span style="color: #7f0055;">byte</span><span style="color: #000000;">[</span><span style="color: #000000;">length</span><span style="color: #000000;">]</span><span style="color: #000000;">;</span>
<span style="color: #000000;">iStrm.read</span><span style="color: #000000;">(</span><span style="color: #000000;">serverData</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span>
<span style="color: #000000;">str = </span><span style="color: #7f0055;">new </span><span style="color: #000000;">String</span><span style="color: #000000;">(</span><span style="color: #000000;">serverData</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span>
<span style="color: #000000;">}</span>
<span style="color: #7f0055;">else </span><span style="color: #3f7f5f;">// Length not available...</span>
<span style="color: #000000;">{</span>
<span style="color: #000000;">ByteArrayOutputStream bStrm = </span><span style="color: #7f0055;">new </span><span style="color: #000000;">ByteArrayOutputStream</span><span style="color: #000000;">()</span><span style="color: #000000;">; </span>

<span style="color: #7f0055;">int </span><span style="color: #000000;">ch;</span>
<span style="color: #7f0055;">while </span><span style="color: #000000;">((</span><span style="color: #000000;">ch = iStrm.read</span><span style="color: #000000;">()) </span><span style="color: #000000;">!= -</span><span style="color: #990000;">1</span><span style="color: #000000;">)</span>
<span style="color: #000000;">bStrm.write</span><span style="color: #000000;">(</span><span style="color: #000000;">ch</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span>

<span style="color: #000000;">str = </span><span style="color: #7f0055;">new </span><span style="color: #000000;">String</span><span style="color: #000000;">(</span><span style="color: #000000;">bStrm.toByteArray</span><span style="color: #000000;">())</span><span style="color: #000000;">;</span>
<span style="color: #000000;">bStrm.close</span><span style="color: #000000;">()</span><span style="color: #000000;">; </span>
<span style="color: #000000;">}</span>

<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"File Contents: " </span><span style="color: #000000;">+ str</span><span style="color: #000000;">)</span><span style="color: #000000;">;</span>

<span style="color: #3f7f5f;">//-----------------------------</span>
<span style="color: #3f7f5f;">// Show connection information</span>
<span style="color: #3f7f5f;">//-----------------------------</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"Host: " </span><span style="color: #000000;">+ http.getHost</span><span style="color: #000000;">())</span><span style="color: #000000;">;</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"Port: " </span><span style="color: #000000;">+ http.getPort</span><span style="color: #000000;">())</span><span style="color: #000000;">;</span>
<span style="color: #000000;">System.out.println</span><span style="color: #000000;">(</span><span style="color: #2a00ff;">"Type: " </span><span style="color: #000000;">+ http.getType</span><span style="color: #000000;">())</span><span style="color: #000000;">; </span>

<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span><span style="color: #7f0055;">catch</span><span style="color: #000000;">(</span><span style="color: #000000;">Exception e</span><span style="color: #000000;">){</span>
<span style="color: #000000;">e.printStackTrace</span><span style="color: #000000;">()</span><span style="color: #000000;">;</span>

<span style="color: #000000;">}</span><span style="color: #7f0055;">finally</span><span style="color: #000000;">{</span>
<span style="color: #3f7f5f;">// Clean up</span>
<span style="color: #7f0055;">if </span><span style="color: #000000;">(</span><span style="color: #000000;">iStrm != </span><span style="color: #7f0055;">null</span><span style="color: #000000;">)</span>
<span style="color: #000000;">iStrm.close</span><span style="color: #000000;">()</span><span style="color: #000000;">;</span>
<span style="color: #7f0055;">if </span><span style="color: #000000;">(</span><span style="color: #000000;">http != </span><span style="color: #7f0055;">null</span><span style="color: #000000;">)</span>
<span style="color: #000000;">http.close</span><span style="color: #000000;">()</span><span style="color: #000000;">;</span>
<span style="color: #000000;">}</span>
<span style="color: #000000;">}</span>

<span style="color: #7f0055;">public </span><span style="color: #7f0055;">void </span><span style="color: #000000;">pauseApp</span><span style="color: #000000;">(){}</span>

<span style="color: #7f0055;">public </span><span style="color: #7f0055;">void </span><span style="color: #000000;">destroyApp</span><span style="color: #000000;">(</span><span style="color: #7f0055;">boolean </span><span style="color: #000000;">unconditional</span><span style="color: #000000;">){ }</span>
<span style="color: #000000;">} </span>

[/code]

Why you should *only* buy cheap HDMI cables?

People buy expensive HDMI cables for their audio/video gear. The justification for that is the LED TV is a very high quality equipment and I need to match it with top-notch cable accessories to get that outstanding viewing experience. So I should buy the most expensive HDMI cable in the market too.

Right?

Wrong! The problem is thinking that the expensive good which is advertised as ‘gold plated’ will give such a premium video quality. HDMI is currently the leading visual technology. But it is also a digital technology. Means unlike analog technologies like A/V out, the signal loss through connectors is negligible. Means, whether your cable is gold plated or not does not make a difference in the video quality.

In HDMI, signal loss issue may happen only on cases where the cable is extremely long – like 20 meters or so. I am sure you are planning to buy a 2 meter cable. So this won’t affect you either.

The only problem with cheap cable will be durability. It may fail fast. But you know, you can buy 2 cheap cables instead of one and still it will come cheaper :-)

I have bought 2 HDMI cables from eBay for Rs 100 each. They are working fine for the last 1.5 years without any issue. So if you are about to buy one, buy a cheap one :-)

Share external harddisk media to the local network

It’s been really hard to share my external harddrive media to the Xbox due to the security settings in Windows. Anyways is now possible to share the folder with ‘Everyone’. After that, Start>Run> Serivices.msc

Go down to Windows Media Player Network Service and change the user to “Local System”. Restart the service (not the machine) and voila, your external harddisk media is shared across your network.

Windows 7 checksums for verification

Recently Microsoft announced that they are ready with Windows 7 RTM (Release to Manufacture) and the original image files are already out for download at many websites. But it is advisable to crosscheck the filehashes to avoid getting infected with rootkits and other malware. A German Microsoft employee had published the Windows 7 checksums. This will come handy when you want to check CRC32/SHA1 hashes.

  • Windows 7 Retail Ultimate E english (x86)
    Name: 7600.16385.090713-1255_x86fre_cliente_en-us_Retail_UltimateE-GRMCEULFRER_EN_DVD.iso
    CRC: 0x953EFBCC
    SHA-1: 0xBC10F09B86DCBAF35B31B0E6FBA7D006ACAAD28D
  • Windows 7 Retail Ultimate E english (x64)
    Name: 7600.16385.090713-1255_x64fre_cliente_en-us_Retail_UltimateE-GRMCEULXFRER_EN_DVD.iso
    CRC: 0x77BE890E
    SHA-1: 0x029DCCEDD7691206010F84CE58343405A4DA92C9
  • Windows 7 Retail Ultimate english (x86)
    Name: 7600.16385.090713-1255_x86fre_client_en-us_Retail_Ultimate-GRMCULFRER_EN_DVD.iso
    CRC: 0xC1C20F76
    SHA-1: 0x5395DC4B38F7BDB1E005FF414DEEDFDB16DBF610
  • Windows 7 Retail Ultimate english (x64)
    Name: 7600.16385.090713-1255_x64fre_client_en-us_Retail_Ultimate-GRMCULXFRER_EN_DVD.iso
    CRC: 0x1F1257CA
    SHA-1: 0x326327CC2FF9F05379F5058C41BE6BC5E004BAA7

Guide: How to verify MD5/SHA1 checksums

Verifying file integrity using md5/SHA1 checksums


Every file is different from another. But with a md5 or SHA1 checksum of the original file, legitimate copies can be verified easily. This is possible because even changing one byte from the original file will make the file hash change. Checking the file integrity like this can avoid possibilities of getting affected by spywares or viruses.Ok. Now you have the md5 checksum and the file to be verified for integrity. Now what? How to verify the checksum?

  • Windows
    Download Microsoft Checksum Integrity Verifier utility OR
    Download HashTab
  • Mac
    Download HashTab for Mac
  • Linux
    Use md5sum utility like

    Code:

    md5sum KNOPPIX_V5.2.1CD-2009-07-04-EN.iso

  • Webservers using PHP
    All the above mentioned methods work thtter when you have direct desktop/console access to the concerned machines. But if it is a webserver (used as a HTTP file proxy, most probably), you can use PHP to easily get the file hash.

    PHP Code:
    <code>&lt;?php
    echo hash_file('md5', 'KNOPPIX_V5.2.1CD-2009-07-04-EN.iso');
    ?&gt;

    Change 'md5' to 'sha1' to get the SHA1 hash instead.

Hope it helps. Please let me know if you use any other technique to verify checksums.

Run your own movie streaming using VLC Player

The largely underestimated VLC Media player can act as a streaming server and is compatible with literally any A/V format. I had a dream of running a streaming movie show at office every friday. This is how it can be done.

What is needed:
1) VLC Player 
2) The movie to be streamed
3) LAN or high speed internet connection

How to do it:

  1. First open VLC player and go to
    File > Open File > Browse File
  2. Select the movie file. Below this control, there is Stream/Save checkbox – select it.
  3. Click on Stream/Save button to get the stream options pane. Choose the MMSH (mainly to make your movie compatible with Windows Media Player) and select port 8080 (You can select any open ports like 80 too. But make sure webservers, Skype etc are not running). Select video codec WMV1 or WMV2 and Audio codec mp3. Now, you are ready to rock and roll. Now your stream options pane should look like this:

Now click ok and again Ok to go back to the main VLC Window. Your movie is started. So, to watch this movie, you need to open the following URL in the Windows Media Player (use the File > Open URL option)

mms://<yourip>:8080

Thats it! Media Player will buffer the movie and start playing. Let me have your suggestions, problems etc etc.

zip and unzip on linux machines

I always used to use tar command to compress and uncompress files in linux. The issue is that it is difficult to remember commandline switches for the command.

So I switched to zip command.

zip -rv9 myfile.zip ./dir_to_compress/

This will zip the directory.
-r : recursive
-v : verbose
-9 : maximum compression

Are we 9? No. We are just two. The trick to remember it :-)

To unzip

 unzip myfile.zip

 

Hope you don’t need any lame tricks to remember it.