Saturday, September 13, 2008

Airtel India blocks IRC Undernet

The Undernet group of servers in the IRC (Internet Relay Chat) system, (us.undernet.org/eu.undernet.org) has been inaccessible since the last week of August for Airtel India users. Despite many complaints by many users to Airtel India over the last 20 days, they are still in denial mode and refuse to acknowledge a problem.

For the uninitiated, The Undernet is one of the oldest and largest realtime chat networks in the world, with approximately 19 servers connecting over 35 countries and serving more than 1,000,000 people weekly. See http://www.undernet.org/ for further information.

The problem is faced by all Airtel ISP users in India across all Indian cities - Delhi, Bangalore, Allahabad, etc.

Since the undernet group of servers generally has a community of vocal and gifted programmers/hackers, it is possible that Airtel has decided to 'silently' block this and claim otherwise. If so, this goes against our right to free speech and expression: http://en.wikipedia.org/wiki/Fundamental_Rights_in_India

If you are an Airtel user, please register a complaint by e-mailing Airtel at your city's customer care address, the list of which are available from:
http://www.airtel.in/wps/wcm/connect/airtel.in/Airtel.In/Home/ForYou/Broadband+Internet/Reach+Airtel#

For example, the complaint e-mail for Bangalore is: care.ncr@airtel.in
Please note - that page DOES NOT WORK in firefox (or any other browser apart from Internet Explorer) - another minus mark against Airtel.

Users have a on-going discussion page at the Undernet forums http://forum.undernet.org/viewtopic.php?f=2&t=9536&st=0&sk=t&sd=a , but are unsure on what to do.

I am a 2Mbps, un-limited download Airtel user. For India, which has poor broadband facilities, that falls into the top segment of broad-band users and I pay a bucket of money for the service.

After Airtel's well known policy of padding your bills with ringtone costs you never use - (and calling them up to fix this never works), this is personally pretty much the limit for me.

Saturday, June 28, 2008

Can't extend ByteBuffer

java.nio.ByteBuffer is not extensible and this really sucks badly. I didn't realize that till today when I thought to write a custom ByteBuffer implementation and then realized that all the constructors had only package visibility.

The thing is that there are many good reasons why you would want a custom implementation of ByteBuffer . Maybe you want to proxy over another ByteBuffer for example; have an optimized view over a larger ByteBuffer to reduce data copying.

It seems that I was not the only one to feel this way. Check out http://forum.java.sun.com/thread.jspa?threadID=693259&messageID=4028590

It appears that not just a few people, but also whole frameworks like Apache MINA have gone ahead and constructed their own ByteBuffer replacements. Check out http://mina.apache.org/report/1.1/apidocs/org/apache/mina/common/ByteBuffer.html which is extensible.

Saturday, May 31, 2008

Access Windows Registry using 'pure' Java

(rehash of my old post since all those wonderful blog post drafts I was planning to publish are unfortunately out-dated or irrelevant)

One can use the private code of Sun's Preferences API to access values of type REG_SZ in the Windows Registry. Stupid hack. Maybe I should make a library out of this. I have used this soooo many times.

The java.util.prefs.WindowsPreferences is the concrete implementation of AbstractPreferences in the Windows platform. This class provides methods like WindowsRegQueryValueEx, etc. Using Reflection, one can use the methods in this class to query string values under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER


Given below is a code-snippet that demonstrates how to get the ProxyServer setting on Windows (this is what IE uses/sets) and the Internet Explorer version


import java.lang.reflect.Method;
import java.util.prefs.Preferences;

public class JavaRegistryHack {

private static final int HKEY_CURRENT_USER = 0x80000001;
private static final int KEY_QUERY_VALUE = 1;
private static final int KEY_SET_VALUE = 2;
private static final int KEY_READ = 0x20019;

public static void main(String args[]) {
final Preferences userRoot = Preferences.userRoot();
final Preferences systemRoot = Preferences.systemRoot();
final Class clz = userRoot.getClass();
try {
final Method openKey = clz.getDeclaredMethod("openKey",
byte[].class, int.class, int.class);
openKey.setAccessible(true);

final Method closeKey = clz.getDeclaredMethod("closeKey",
int.class);
closeKey.setAccessible(true);

final Method winRegQueryValue = clz.getDeclaredMethod(
"WindowsRegQueryValueEx", int.class, byte[].class);
winRegQueryValue.setAccessible(true);
final Method winRegEnumValue = clz.getDeclaredMethod(
"WindowsRegEnumValue1", int.class, int.class, int.class);
winRegEnumValue.setAccessible(true);
final Method winRegQueryInfo = clz.getDeclaredMethod(
"WindowsRegQueryInfoKey1", int.class);
winRegQueryInfo.setAccessible(true);


byte[] valb = null;
String vals = null;
String key = null;
Integer handle = -1;

//Query Internet Settings for Proxy
key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
handle = (Integer) openKey.invoke(userRoot, toCstr(key), KEY_READ, KEY_READ);
valb = (byte[]) winRegQueryValue.invoke(userRoot, handle.intValue(),
toCstr("ProxyServer"));
vals = (valb != null ? new String(valb).trim() : null);
System.out.println("Proxy Server = " + vals);
closeKey.invoke(Preferences.userRoot(), handle);

// Query for IE version
key = "SOFTWARE\\Microsoft\\Internet Explorer";
handle = (Integer) openKey.invoke(systemRoot, toCstr(key), KEY_READ, KEY_READ);
valb = (byte[]) winRegQueryValue.invoke(systemRoot, handle, toCstr("Version"));
vals = (valb != null ? new String(valb).trim() : null);
System.out.println("Internet Explorer Version = " + vals);
closeKey.invoke(Preferences.systemRoot(), handle);

} catch (Exception e) {
e.printStackTrace();
}
}


private static byte[] toCstr(String str) {
byte[] result = new byte[str.length() + 1];
for (int i = 0; i < str.length(); i++) {
result[i] = (byte) str.charAt(i);
}
result[str.length()] = 0;
return result;
}

Google Collections now in Maven repository

(This blog has been dead for like forever - so many draft entries that were never turned to posts over the last year, but *shrug*)

Google Collections has now been mavenized, or to be more precise - the artifacts are present in the maven repository. Check out Maven Repo1 and the issue that reports this.

Just add the below to your &lt;project&amp;gt;.pom and you are good to go.



<dependency>
<groupId>com.google.code.google-collections</groupId>
<artifactId>google-collect</artifactId>
<version>snapshot-20080321</version>
</dependency>






(Google collection's is like the Apache commons collections but generified)

Friday, January 25, 2008

My first Ruby Program - the Icon Indexer

Well.. I work a lot on eclipse and I always wanted to get the complete eclipse icon set from my eclipse directory (for my eclipse rich client applications) and have a nice index.html file to view the same. Decided to spin a ruby program to do the job.

(Yeah...I do know about ISharedImages.. but that doesn't give everything)


require 'find'

class IconIndexer
def index(base_dir)
idx_path = base_dir + '\index.html'
idxh = File.new(idx_path, "w")
puts "Created index file at " + File.expand_path(idx_path)
puts "Scanning image files (.gif/.png) from #{base_dir} ..."
idxh.puts <<-EOS
<html>
<head>
<title>Icon Index generated for #{base_dir} on #{Date.today()}</title>
</head>
<body>
<table>
EOS
cnt = 0;
ncols = 3;
icon_size = 3 * 1024;

# Scan base_dir get all gifs/png's less than 'icon_size' kb and
# create index html consisting of 'ncol' sized table with these images.
# ofcouse this is a dumb program since it doesn't take img dimentions into account
# but nvm.
Find.find(base_dir) do |path|

if File.extname(path) =~ /(.gif|.png)/ and File.size(path) < icon_size
if cnt % ncols == 0
idxh.puts "<tr>\n"
end
img_path = File.expand_path(path);
html = "<td><a href='#{img_path}'><img border='0' src='#{img_path}'/></a></td>"
cnt+=1
idxh.puts(html)
if cnt % ncols == 0
idxh.puts "</tr>\n"
end
end
end

idxh.puts <<-EOS
</table>
</body>
</html>
EOS

end
end

indexer = IconIndexer.new()
if ARGV[0]
indexer.index(ARGV[0])
else
script_name = File.basename(__FILE__);
puts "Usage: #{script_name} <search_dir>"
end