Wednesday, May 27, 2009
The cardamom habit - Carry it wherever you go
A soldier came running to the king, and told him about how the Europeans were loading Spice rhizomes onto their ships. The soldier was scared that the Europeans will never come back for spices if they could grow it in their own country. The King laughed at the foolishness of the soldier and said "They can steal the seeds but they cant steal our monsoon".
Although its easy to grow cardamom, it rarely blossoms outside the tropics. So the king was correct in his optimism, but the monsoons brought not only rain but also Europeans to India. So the next time you plan to leave the tropics, don't forget to carry it with you. Habits die hard
Friday, May 22, 2009
Flags that have appeared in Google logos - till April 2009
- US National flag for the government related sites search. (Uncle Sam search)
- The French National flag appeared in the Google logo for Bastille Day
- The Canadian National flag appeared in the Google logo for Canada Day 2001
- The Swiss National flag appeared in the Google logo for Swiss National Day 2001
- The South Korea National flag appeared in the Google logo for Korean Liberation Day or Gwangbokjeol 2001
- St George's Cross flag or National flag of England appeared in the Google logo for St George' Day 2002.
World Turtle Day - Fake Google Logo?
Tomorrow 23rd May is World turtle day. It was started in the year 2000 by American Tortoise Rescue to bring about awareness about turtles and tortoises. It is celebrated in different ways like:
- Dressing up like turtles
- Turtle and tortoise Conservation efforts
- Rescuing of turtles and tortoises from illegal captivity
The main danger to turtles comes from human beings and many turtle species are endangered today due to excessive hunting. The flesh of turtles is considered a delicacy in many cultures. Turtle soup which is made from the flesh of the green turtle or the snapping turtle can lead to the killing of large number of turtles. Few endangered species of turtles are also killed for food, leading to further reduction in the population of the endangered species.
Turtles can be saved from the fate of the dodo by bringing about awareness among people. Hope google decides to support the turtle conservation efforts by putting a logo on World turtle day.If they can come up with a famous Turtle day Google logo, it will do a lot to help conserve turtles. Until then this fake google logo has to do.
International Day for Biological Diversity - Invasive Alien Species
The decline or elimination of native species can occur through:
- Competition(Ex: Lantana camara, also known as Spanish Flag reproduces and spreads very quickly and poses a threat to other native species in few eco-systems)
- Predation (EX: Rattus rattus, commonly known as the ship rat has caused extinctions and catastrophic declines of native birds on islands)
- Transmission of Pathogens (Ex: Pathogens such as avian influenza A(H5N1)are attacking various organisms.)
- Disruption of natural eco-system(Ex: Eichhornia crassipes, commonly known as Common Water Hyacinth has lead to disruption many ecosystems by choking lakes and making them unfit for fish.)
The problem can be best tackled by raising awareness among individuals and cooperation between governments. However, it might not be possible to stop the movement of organisms (especially microbes and plants) from one region to another in this era of globalization.
Wednesday, May 20, 2009
The Reluctant Fundamentalist - Mohsin Hamid
Written completely as the narrative of one person, the narrator even poses the questions that the American might have felt like asking. More than once, I felt the novel was written in urdu and then translated into English, no not because of any lack in the language, but of the way in which the narrative proceeds. One simply can’t write few eastern ideas in a western language, but Hamid seems to have succeeded in this as well.
Furthermore the novel seemed to be the expanded form of a short story written in the Afsana form of Urdu literature. The existence of a short story version of the novel, “Focus on Fundamentals” seems to hint at the same.
When Mohsin talks about Lahore with its chai and jallabi’s, one could relate it to any one of the many Indian cities. The threat of a nuclear catastrophe and the futility of a bloody war also echo similar sentiments from across the border.
Windows Process Monitor in java
These simple set of functions make use of the windows tasklist.exe utility to perform following functions:
- Alert when a particular process, service, module is started.
- Alert when memory usage of any particular or any process exceeds a certain value.
- Alert if any particular or any process is not responding.
- Alert if CPU Time for a particular process exceeds a certain value.
- Monitor if a particular number of instances of a service, process, and module is running. If it falls below or goes above the mentioned number of instances- generate alert.
import java.io.*;
import java.util.*;
public class GetProcess {
public static void main(String[] args){
//few example uses of the functions.
System.out.println(CheckIfProgramXIsNotResponding(""));
System.out.println(CheckIfProgramXIsUsingMoreThanYKBOfMemory("java.exe",4200));
System.out.println(CheckIfProgramXIsUsingMoreThanZOfCPUTime("System", 0,0,1));
System.out.println(CheckIfNInstancesOfProgramXAreExecuting("svchost.exe",5));
System.out.println(CheckIfNInstancesOfServiceXAreRunning("MDM",1));
System.out.println(CheckIfNInstancesOfModuleXAreRunning("ntdll.dll",29));
}
/*These functions can be used along with a configuration file or a front end to perform monitoring of Windows systems.*/
private static boolean CheckIfProgramXIsNotResponding(String ProgName){
//returns true if given program is NOT RESPONDING. If no argument is passed, returns true if any program is not responding.
String argument="tasklist.exe /NH /FI ".concat("\"").concat("STATUS eq NOT RESPONDING").concat("\"");
return checkProcessInfo(argument, ProgName);
}
private static boolean CheckIfProgramXIsUsingMoreThanYKBOfMemory(String ProgName,int MemoryInKb){
//returns true if given program is using more than Y KB of Memory.If no argument is passed, returns true if any programs memory is more than Y KB.
String line,argument="tasklist.exe /NH /FI ".concat("\"").concat("MEMUSAGE gt ")+MemoryInKb;
argument=argument.concat("\"");
return checkProcessInfo(argument, ProgName);
}
private static boolean CheckIfProgramXIsUsingMoreThanZOfCPUTime(String ProgName,int Hours,int Minutes,int Seconds){
//returns true if given program is using more than Z CPUTime.If no argument is passed, returns true if any programs memory is using more than Z CPUTime.
String line,argument="tasklist.exe /NH /FI ".concat("\"").concat("CPUTIME gt ")+Hours+":"+Minutes+":"+Seconds;
argument=argument.concat("\"");
return checkProcessInfo(argument, ProgName);
}
private static boolean CheckIfNInstancesOfProgramXAreExecuting(String ProgName,int n){
//returns true if N instances of ProgramX are executing.
String line,argument="tasklist.exe /NH /FI ".concat("\"").concat("IMAGENAME eq ").concat(ProgName).concat("\"");
return checkProcessCount(argument,ProgName,n);
}
private static boolean CheckIfNInstancesOfServiceXAreRunning(String ProgName,int n){
//returns true if N instances of Service X are running.
String line,argument="tasklist.exe /NH /FI ".concat("\"").concat("SERVICES eq ").concat(ProgName).concat("\"");
return checkProcessCount(argument,"",n);
}
private static boolean CheckIfNInstancesOfModuleXAreRunning(String ProgName,int n){
//returns true if N instances of Module X are running.
String line,argument="tasklist.exe /NH /M ".concat(ProgName);
return checkProcessCount(argument,"",n);
}
private static boolean checkProcessInfo(String argument,String ProgName){
String line;
try {
System.out.println(argument);
Process p = Runtime.getRuntime().exec(argument);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (!line.trim().equals("")) {
if(line.startsWith(ProgName)){
return true;}//return status
}
}
input.close();
}
catch (Exception err) {
err.printStackTrace();
}
return false;
}
private static boolean checkProcessCount(String argument,String ProgName,int n){
String line;
int count=0;
try {
System.out.println(argument);
Process p = Runtime.getRuntime().exec(argument);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (!line.trim().equals("")) {
if(line.startsWith(ProgName)){
count++;}
}
}
input.close();
}
catch (Exception err) {
err.printStackTrace();
}
System.out.println(count);
if(n==count){
return true;}//return status
return false;
}
}
Tuesday, May 12, 2009
Sequential Screen Capture Utility
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
public class ScreenCapture {
public static void main(String[] argv) throws Exception{
int i,time;
String option="S";
if(argv.length > 0) {
try {
time = Integer.parseInt(argv[0]);
for(i=0;i< time;i++){
captureandstorescreenshot();}}catch(NumberFormatException nfe) {
if (argv[0].equalsIgnoreCase("-help"))
{System.out.println("ScreenCapture Utility \n\n Usage:Run the program to capture screenshots for the next x seconds using the command [javac ScreenCapture x].\n Ex:javac ScreenCapture 20\n");
}
else if (argv[0].equalsIgnoreCase("-SE"))
{
while(!option.equalsIgnoreCase("X")){
InfiniteLoop t = new InfiniteLoop();
if(option.equalsIgnoreCase("S")){
t.start();}
Console console = System.console();
option= console.readLine("Enter E to end,S to start and X to exit?");
if(option.equalsIgnoreCase("E")){
Thread.sleep(1);
t.interrupt();}
}
}
else{
System.err.println(argv[0]+" is not a valid number of seconds.'javac ScreenCapture -help' for syntax.");
System.exit(-1);}}}
}
public static void CaptureAndStoreScreenShot(){
try{
Calendar rightNow = Calendar.getInstance();
Dimension scrensize = Toolkit.getDefaultToolkit().getScreenSize();
Robot robot = new Robot();
BufferedImage img = robot.createScreenCapture(new Rectangle(scrensize));
//difference (measured in milliseconds) between the current time and midnight, January 1, 1970 UTC
String filename ="screen"+System.currentTimeMillis()+".jpg";
ImageIO.write(img, "JPG", new File(filename));
}catch(Exception e){return;}
}
}
class InfiniteLoop extends Thread
{
public void run(){
for( ; ;){
ScreenCapture.CaptureAndStoreScreenShot();
if (Thread.interrupted()) {
// System.out.println("Interrupted");
return;
}
}
}
}
The below error occurs in older versions(Pre java 2) while interrupting the thread. It seems like a bug in older versions of java.
AWT blocker activation interrupted:
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:429)
at sun.awt.AWTAutoShutdown.activateBlockerThread(AWTAutoShutdown.java:30
9)
at sun.awt.AWTAutoShutdown.setToolkitBusy(AWTAutoShutdown.java:226)
at sun.awt.AWTAutoShutdown.notifyToolkitThreadBusy(AWTAutoShutdown.java:
118)
at sun.awt.windows.WToolkit.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:308)
at java.lang.Class.newInstance(Class.java:261)
at java.awt.Toolkit$2.run(Toolkit.java:760)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:739)
at ScreenCapture.CaptureAndStoreScreenShot(ScreenCapture.java:44)
at InfiniteLoop.run(ScreenCapture.java:58)