Harnessing energy from ordinary matter is only practical when the matter is unstable. Most ways are made possible by nature. Hydro-electro power generation relies on the sun and the wind to carry water vapour to mountains. Wind turbines work thanks to air pressure differences. Nuclear power will not be here today if it wasn't for radioactively unstable materials. Unstability in the sun itself gives us solar power that generates energy for living things most importantly.
Human population growth, however, demands more and more energy. Cheap energy, that is. Building a power station is a big investment. It's often forgotten that the capital is not on the station alone. Distributing the power probably costs much more then the station. Portable energy generation, by contrast, does not require huge initial capital investments.
In addition to solar energy, water is perhaps the next source of life. It may also be the next source of energy for non-biological purposes. We have harnessed its energy from its gravitational unstability in the form of hydro-electro power. But what about the portable generation?
Saturday, November 28, 2009
Saturday, October 24, 2009
D Programming Language
I have recently started learning the D programming language. I have heard about it for a while but had never attempted to try it.
It was a pretty good experience, but I have 2 major issues. The first one is with the null pointer exception handling. There is none in D. If there is the application will just terminate with a segmentation fault. This I consider is a very serious issue. Null pointer exception is a fact of life in software applications. We are talking about millions of lines of code and not every programmer would check for it before calling an instance method. Java handles it as an exception which means it can be caught gracefully. Imagine you have a server application that serves hundreds of users. You don't want the whole application to segfault if there is a null pointer exception.
The second issue I have is with on-line documentation. Other than the almost useless Hello World examples I can't seem to find better ones. There are books, but in my humble opinion there should be free (gratis) information, especially if this is relatively a new subject. I do buy books because I realise I need to support the IT industry (and also because books are tax-deductible). But I am not open to buy books about a subject that is not yet well known.
It was a pretty good experience, but I have 2 major issues. The first one is with the null pointer exception handling. There is none in D. If there is the application will just terminate with a segmentation fault. This I consider is a very serious issue. Null pointer exception is a fact of life in software applications. We are talking about millions of lines of code and not every programmer would check for it before calling an instance method. Java handles it as an exception which means it can be caught gracefully. Imagine you have a server application that serves hundreds of users. You don't want the whole application to segfault if there is a null pointer exception.
The second issue I have is with on-line documentation. Other than the almost useless Hello World examples I can't seem to find better ones. There are books, but in my humble opinion there should be free (gratis) information, especially if this is relatively a new subject. I do buy books because I realise I need to support the IT industry (and also because books are tax-deductible). But I am not open to buy books about a subject that is not yet well known.
Saturday, September 12, 2009
Using the enemy's sword?
I have been reading about inter-religion debates. In this particular instances, claims that the Bible contains references to Muhammad and claims that the Koran confirms the divinity of Jesus. Obviously, some Muslims use the former and some Christians use the latter to attack each other.
I find it contradictory that people use other people's scripture as a basis for their argument. When people say that certain passages in the Bible predict the coming of Muhammad, are they saying that they believe in the Bible? The Bible contains much more passages about the beliefs of Judaism and Christianity. Do they also believe in those passages? I know that some Muslims believe that the Bible has been corrupted. In this light, are they saying that only those pro-Islam passages are still un-corrupted?
Likewise, what are Christians who use the Koran argument implying? Do they selectively believe certain passages of the Koran while ignoring the passages that reject Jesus' divinity? I think the real argument they are presenting is that the Koran has contradictions, rather than for Muslims to believe that Jesus is God.
What's the point? Exactly.
I find it contradictory that people use other people's scripture as a basis for their argument. When people say that certain passages in the Bible predict the coming of Muhammad, are they saying that they believe in the Bible? The Bible contains much more passages about the beliefs of Judaism and Christianity. Do they also believe in those passages? I know that some Muslims believe that the Bible has been corrupted. In this light, are they saying that only those pro-Islam passages are still un-corrupted?
Likewise, what are Christians who use the Koran argument implying? Do they selectively believe certain passages of the Koran while ignoring the passages that reject Jesus' divinity? I think the real argument they are presenting is that the Koran has contradictions, rather than for Muslims to believe that Jesus is God.
What's the point? Exactly.
Friday, July 24, 2009
Command and Data
Just logging in and out to an FTP server is not really interesting, isn't it? I tried the next logical thing one would do once logged in, getting the list of files from the current directory.
Didn't quite work. Kept getting connection error. I expected the file list would be returned in the input stream like the previous commands I tried. Maybe it had something to do with the active and passive modes in FTP. Googling "FTP passive mode" got me a very good link, Active FTP vs. Passive FTP, a Definitive Explanation.
It became clear after reading that there are 2 ports involved, command and data. The previous commands I tried happen not to have data. Now I understand what RFC 959 means when it says to "listen" on a port. You need to a ServerSocket in order to "listen". Of course, "listening" must be done on a separate thread.
Out of curiosity I also tried the old faithful ftp command line. Passing -d as an argument showed me the raw commands in the background. I quickly discovered that the "ls" client command actually issues PORT before LIST.
os.write("LIST\r\n".getBytes());
// readInputStream . . .
Didn't quite work. Kept getting connection error. I expected the file list would be returned in the input stream like the previous commands I tried. Maybe it had something to do with the active and passive modes in FTP. Googling "FTP passive mode" got me a very good link, Active FTP vs. Passive FTP, a Definitive Explanation.
It became clear after reading that there are 2 ports involved, command and data. The previous commands I tried happen not to have data. Now I understand what RFC 959 means when it says to "listen" on a port. You need to a ServerSocket in order to "listen". Of course, "listening" must be done on a separate thread.
Out of curiosity I also tried the old faithful ftp command line. Passing -d as an argument showed me the raw commands in the background. I quickly discovered that the "ls" client command actually issues PORT before LIST.
final int port = 12345; // just a random port number
Thread t = new Thread(new Runnable(
public void run() {
ServerSocket datalistener = new ServerSocket(port);
Socket data = datalistener.accept();
// readInputStream . . .
data.close();
datalistener.close();
}
)};
t.start();
String ftpclientIP = ftpclient.getLocalAddress()
.getHostAddress().replace('.', ',');
String portargs = ftpclientIP + (port/256) + (port%256);
os.write(("PORT " + portargs + "\r\n").getBytes());
os.write("LIST\r\n".getBytes());
Simple Old Technology
Yesterday I had an idea to write an FTP client in Java. I have always known that this is a simple old piece of technology. Old, but still widely used until now. I don't understand why Sun doesn't have a simple implementation in its Java Standard Edition.
Anyway, I remembered that there was an RFC on FTP. A little bit of googling got me the paper that I wanted, RFC 959. To be honest, it wasn't as simple as I would expect it to be. That didn't stop me from starting coding. The first thing that came to my mind was to create a Socket to an FTP server on port 21 and start sending FTP commands.
Next, I tried logging in. I quickly found out that you had to end each command with CRLF (\r\n).
Anyway, I remembered that there was an RFC on FTP. A little bit of googling got me the paper that I wanted, RFC 959. To be honest, it wasn't as simple as I would expect it to be. That didn't stop me from starting coding. The first thing that came to my mind was to create a Socket to an FTP server on port 21 and start sending FTP commands.
Socket ftpclient = new Socket("ftp.someserver.com", 21);
InputStream is = ftpclient.getInputStream();
do {
byte[] b = new byte[1024];
int len = is.read(b);
System.out.println(new String(b, 0, len));
} while (is.available() > 0);
Next, I tried logging in. I quickly found out that you had to end each command with CRLF (\r\n).
OutputStream os = ftpclient.getOutputStream();
os.write("USER anonymous\r\n".getBytes());
// readInputStream . . .
os.write("PASS guest\r\n".getBytes());
// readInputStream . . .
os.write("QUIT\r\n".getBytes());
// readInputStream . . .
Saturday, July 18, 2009
Punish the good, reward the bad
Sydney CityRail ticketing system. Some stations do not have automatic ticket readers. Where I normally catch my train to work is one of them. What's the issue? If you normally buy weekly tickets, it can happen that you forget that your ticket has expired. So there you are travelling happily on the train without realising what is going to happen when you are about to pass the exit reader in a CBD station. Talk to a station attendant and you'll likely to get a fine.
See, if they had installed a reader on every station, you would have to present your ticket on entry. If your weekly ticket has expired, not a problem, just buy a new one.
See, if they had installed a reader on every station, you would have to present your ticket on entry. If your weekly ticket has expired, not a problem, just buy a new one.
Subscribe to:
Comments (Atom)