Friday, August 5, 2011

Android EditText set to numeric

I am impressed with Android. I faced some situations which seemed to need some detailed care but Android has very simple solutions to those. Setting the EditText to accept only numbers is one of them. I was going to do what I usually do with Java, create my own NumberField class that extends JTextField and add method to check if the values are numeric, as well as perform other numerical operations or use a listener to validate the field when they are entered.

Android has a very simple solution for this. When implemented, the user will not even be able to type in any text in that field at all.

In the XML file where you create and set properties of the EditText field, add the following item:

android:numeric="decimal|signed"

This will let the user enter any number - integer, decimal as well as signed negative numbers but no text. The user will be able to enter only one '.' in the field which is the decimal. Pretty neat isn't it? Especially for the app that I am working on that has numerous fields that are need to be numeric only. As some of the fields in my app are created using codes, I had to set those properties in my code. The way to do that is:

textEntry.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_DECIMAL|InputType.TYPE_NUMBER_FLAG_SIGNED);

Hope this is useful. Will post more ideas and tips in the next posts.

Wednesday, July 6, 2011

Haiku working great from hard drive

I finally got Haiku working from hard drive. I got some help from the Haiku chatroom to get it up and running. Ran the bootable command to make the Haiku partition bootable and then played with the grub a little bit to try and get it working. It seems there is some problem with grub and I am not that familiar with grub and linux to fix it. Even though grub did find the Haiku drive when I ran then update-grub command, when I tried to boot grub would throw some error messages. I was able to type in the same set of instructions from the grub prompt and Haiku would boot just fine.

The instructions I typed in the grub prompt are:

set root=(hd0,7)
chainloader +1
boot

I set the same root in the 40_custom file and ran update-grub and it found Haiku in that partition upon update. Still, for some reason it would not boot.

I was surprised how less memory and processor Haiku was using. It was around 100 MB RAM...that was all it was taking!..and it was FAST and very responsive. It almost seemed unreal, especially because it wasn't using much processor capacity and it was still fast. I tested a few Haiku apps, they all worked great. I will start playing with it more and post what I find. So far I love it. I believe Haiku will make a mark in the OS arena. It may take some time before they come up with a stable version as well as more apps. It will be certainly interesting to see.

Tuesday, July 5, 2011

Windows 7 Vs Ubuntu Linux Vs Haiku

My new laptop came with Windows 7. I was excited, but not very, because it’s just another Windows operating system. I do like Windows 7, but I always wanted to try alternative operating systems. I have tried Ubuntu installed in a USB earlier, so this time I decided to install it on my hard drive.

I made a partition for Linux, it was pretty easy. I used Windows to make the partition. Once I made the partition, I used the Windows Ubuntu installer located here: http://www.ubuntu.com/download/ubuntu/windows-installer . This, I believe is the simplest way to install Ubuntu to run alongside Windows. It was pretty easy and upon reboot, the Windows menu was updated and it prompted me with two alternatives “Windows 7” and “Ubuntu”. One I select Ubuntu, it will take me to the Grub menu where it again lists both Ubuntu and Windows 7, as well as the Windows 7 recovery partition.

Ubuntu was fast, easy to use and came with the free Libre Office. I haven’t worked much with it yet, but from what I saw it was very similar to Open Office, and they both are very good alternatives to MS Office suite. And hey, they both are free!!!. So far I love Ubuntu and have been making it a point to choose the “Ubuntu” option at log in as often as I can. Now with two operating systems running in parallel I would not panic too much if my Windows starts acting up! I will have all my data in a drive dedicated only for data files, that way my data files are not at the mercy of Windows' reliability.

Another OS that I wanted to try recently was Haiku. I have tried it in the past installing it in a USB drive, but it did not work that great with my USB and I wanted to give it another chance. I followed the instructions and created a Live CD and using which I formatted another partition that I created for this, and installed Haiku in that partition. It seems after that I need to add Haiku to my Grub, if I am using Linux along with Haiku. I tried, following the instructions in the website but haven’t got much luck so far. I am currently working on it and may post this question on the Haiku forums. It still works great from the Live CD though, but I really want it working from the hard drive to get the full experience

For those who are not familiar with Haiku, I really recommend you read up on that. It’s a really cool operating system based on the BeOS. It’s fast, light weight and heavily multi-threaded. I was really excited as I was reading about Haiku. I hope they have good success with this and I am even considering contributing to some of the Haiku projects myself. It is really worth checking out. Their website is: http://haiku-os.org/

I will post more on these operating systems in the coming posts.

Saturday, April 30, 2011

What is orthorexia? A new dangerous disorder?

I am not sure if it’s just coincidence or if there’s something behind it, but the word ‘Orthorexia’ has been showing up in different forms in different articles lately in the online media. So, what is orthorexia? The word ‘Orthorexia’ is derived from two Greek words ‘ορθο’ (ortho meaning ‘correct’ or ‘right’) and ‘όρεξις’ (orexis meaning ‘appetite’). So it means something like ‘right-appetite’ or ‘correct diet’. Basically it seems orthorexia is an eating disorder where the sufferers avoid food with chemicals and pesticides and preservatives and eat only healthy food; they watch what they are eating. There is an innate desire in many of us to do things the right way. Whether it is doing our jobs, or dealing with relationships or writing a computer program or taking pictures or writing a blog or just about anything basic including keeping the house clean, wearing clean clothes, drinking clean water, breathing clean air, and…yes...eating the right food. Why is eating the right food suddenly a ‘mental disorder’?

The word itself is not a new word; it was formed in 1997 but has been given new life recently by the media. There was a time when people cared in great detail for the food they ate. They picked the right food items that would supply them with the nutrition that their bodies needed and prepared them with the right kind of ingredients to make the dishes tasty, natural and healthy. This was obvious and part of their lives, and part of their general knowledge. If you ask some ‘old timers’, especially from cultures that have not modernized very much they would go in detail about how certain food items may cause certain reactions and how certain food items can help deal with certain conditions in the body, etc.

As societies modernized and things became more and more complicated, there were other things that people increasingly started focusing on, including entertainment. People suddenly felt that preparing food, and understanding food is an onerous chore and that is when the processed food industry was born. It was so convenient to buy food from the shelves and eat it without doing anything to it, or at the minimum heat it up. Gradually people became less and less knowledgeable about food, and the various nutrients contained in various food items and food became something that is tasty, filling and easy to get and something that is eaten so that they don’t feel hungry to do the real things like entertaining themselves or focusing on work. How often have we heard things like “The game is about to start in 30 mins, I’m just gonna order pizza”, or “I have an important report that I need to finish, I’m just going to get a sandwich”.

The greatest problem to this is not the obvious health problems and decline in general health among the public but it is the decrease in general knowledge about food. If this trend continues, people may not even know what goodness is in tomatoes and how fish is good for us and what is the importance of eating raw vegetables. All they would care for is keeping their bellies filled with the tastiest food gotten the easiest way possible and repeating after whatever information the processed food industry keep feeding them; almost like the “The plants need electrolytes” scene from the movie “Idiocracy”.

The good thing is there has been an increase in awareness among the public and even a desire to know more about food, and consumption of more fresh and organic food items. People are increasingly starting to avoid processed food, and food that is devoid of nutrients and colored and flavored with numerous chemicals and kept preserved with preservatives. This is certainly not good news for the processed food industry. So why not call a return to ‘normality’ as something ‘abnormal’, a ‘mental disorder’? It may not suddenly “enlighten” people and cause them to return to processed food, but atleast it may slow down the trend, or make some ‘new converts’ or ‘undecided’ people think and wonder, if that is really a weird disorder. Even if it can give the processed food consumers some new point to debate against their own well-being, that itself is a huge help for the processed food industry. That I believe is the reason behind the “discovery” of this new “mental disorder”. Hopefully there are enough people who can think rationally and are knowledgeable and wise enough to decide what is good for them instead of buying theories from these “experts”.

Tuesday, April 12, 2011

Java Multiplication Table Program

This is the program to create multiplication table in Java. It's a quite simple, basic level program. It arranges the numbers to the right hand side of the 'column'. Here it is:

int[][] multtable = new int[13][13];

for(int i=0; i<=12;i++){
for(int j=0; j<=12;j++){
//Print the first row (i==0) which is the column header. 4 spaces before the number if number <10 else 3 spaces
if((i==0)&(j>0)){
multtable[0][j] = j;
System.out.print((multtable[i][j] < 10? " ":" ") + multtable[i][j]);
continue;
}
//Print the first column (j==0) which is the numbers (i) itself. 4 spaces before the number if number < 10 else 3 spaces
if((i>0)&& (j==0)){
multtable[i][0] = i;
System.out.print((multtable[i][j] < 10? " ":" ") + multtable[i][j]);
continue;
}
//For other rows (>0) and columns(>0) multiply i & j to create the multiplication table
multtable[i][j] = i*j;
//For values < 10 print 4 spaces before the number
if (multtable[i][j]<10)
System.out.print(" "+multtable[i][j]); else
//For values <100 print 3 spaces before the number
if (multtable[i][j]<100)
System.out.print(" " + multtable[i][j]);else
//Other values (<10) print 2 spaces before the number
System.out.print(" " + multtable[i][j]);
}
//Print line for next row
System.out.println();
}

The output looks like this:

Sunday, April 10, 2011

Could Bloom Energy be the future of electricity production?

Almost a year ago, a company called 'Bloom Energy' hit the headlines. The founder of the company K. R. Sridhar gave presentations and interviews on what it is, how it works and how it can solve many inefficiencies in current electricity production and distribution. What was more surprising was Bloom Energy has been producing fuel cells and has installed them in corporate offices of several big corporations like Google, Bank of America, Walmart, etc. Almost sounded like some undercover operation.

A brief explanation on what it actually is:

Bloom Energy uses hydrocarbon based fuel cells, which it calls 'Bloom Box' or 'Bloom Energy Server' that takes in hydrocarbon (eg. Natural gas) and passes it through plates coated with a special catalyst. One of the plates is the cathode and another the anode. The catalyst helps break down the hydrocarbon into CO2, H2O and electricity. We are not going to look into the details of the technology itself, but we are going to focus more on how a concept like this can revolutionize production and distribution of electricity.

Could Bloom Energy really deliver? It seems like a very good idea. By looking at the concept, it seems to solve two major inefficiencies in the current system:

1. Production inefficiencies
2. Distribution inefficiencies

1. Production inefficiencies:

Currently most electricity is produced by converting mechanical energy into electrical energy by driving an electric generator. The mechanical energy to drive the generator is derived from steam which in turn derives its energy from coal, sun or radioactive elements. Some are more direct, like wind energy farms for example, energy from the wind is converted to mechanical energy which is then converted to electricity, and natural gas and diesel power plants also involve fewer steps. The most direct do far has been using solar cells but they are very expensive and the technology is still young. But as we have seen in most cases multiple energy conversions are involved before we get the final product - electricity. The more the number of conversions, the higher the energy losses. In each step of the conversion process energy is lost A quick look at some of the popular processes of electricity generation:

Coal, Solar (Thermal energy based), Nuclear power plants:

Heat from Coal, Sun, Nuclear reaction -->Convert water to steam-->High temperature high pressure steam runs the turbine-->Turbine runs the generator-->Generator produces electricity.

Natural gas, diesel power plants:

Natural gas burns to run the turbine/Diesel burns in IC engine -->Runs the generator-->Generator produces electricity

Wind power plants:

Wind turns the turbine-->Turbine runs the generator-->Generator produces electricity

On the other hand, Bloombox or the Bloom Energy server as it is called directly converts chemical energy in fossil fuels into electricity, producing CO2 and H2O in the process. In short it would look like:

Natural Gas-->Electricity.

This makes the Bloom Energy server very efficient.

Is this the only fuel cell capable of converting chemical energy directly to electricity? No, there are several, especially ones based on Hydrogen. But that again poses serious problems, like production of Hydrogen, which again costs a lot of energy, and distribution and storage of Hydrogen, which is a highly explosive gas.

Most cities already have natural gas pipelines and several new gas wells have come up recently with urban gas drilling, and natural gas is so easy to extract and distribute. These factors give natural gas based fuel cells a definite advantage over Hydrogen fuel cells

Hence, considering production efficiencies of several power plants and technologies out there, the bloom box certainly seems to be a clear winner.

2. Distribution inefficiencies:

Most power plants are situated very far from major consumers. No one wants a coal or nuclear power plant in the suburb or downtown. Even clean energies like wind and solar need vast areas of land, which means they need to be located far away from civilization. The current model of electricity distribution is very inefficient. Eletricity is produced in power plants situated far from major cities and industries and is then supplied to the grids. The grids on the other hand are connected to several grids and switching stations that control the distribution of power based on load requirements. Then there are sub-stations that are connected to the grid that 'step-down' the high voltages for local distribution, which is then even stepped-down for household distribution using transformers.

In brief, the model is more of a 'centralized' model than 'localized'. Such a centralized model requires vast distribution networks that may run thousands of miles, multiple switching stations, multiple transformers performing multiple voltage conversions. Before the electricity reaches the consumer, it is switched from one grid to another, from one sub-station to another, the voltages 'stepped-up' and 'stepped-down' multiple times using transformers before finally reaching the consumer.

Similar to what we saw in the 'Production inefficiencies' section, the more the number of voltage conversions, the more the losses. The farther the electricity is transported the more the losses. Transmission and distribution losses are a major inefficiency in the current model of electricity production and distribution.

Moreover, such is model is very susceptible to natural disasters and is vulnerable to terrorist or military attacks.

Bloom Energy model is very localized. Energy is produced right where it is needed. No transmission or distribution, no need for voltage conversions (Unless a higher or lower voltage is desired). It could be right in your backyard, or in a neighborhood supplying for the whole community. Every office building may have one in its block. There no one sub-station to fail and plunge a whole suburb into darkness. There can even be mini grids within a city or a town with many bloom boxes backing each other up in case one fails or one is shut down for maintenance. Such mini grids may be much more efficient than transporting electricity half the way across the country.

When considering distribution, the Bloom Energy is again a clear winner.

Bloom Energy certainly has good prospects in the future. The model is very attractive and efficient. Even though it still uses fossil fuels, it makes the best use out of fossil fuels, and hence can still be considered 'green'. It is still far less polluting than other fossil fuel based plants. There may be exciting new turns in the near future in the energy field.

Monday, April 4, 2011

Fresh Beef Jerky

I heard this funny story from this guy I know. He was going down the freeway somewhere way out in the country when he saw the sign "Fresh Beef Jerky, Take the next exit". He loves beef jerky and he got pretty excited when he saw the sign. The pulled off the freeway, followed the signs to the store and picked a few packages.

At the check out counter he stuck a conversation and asked the guy checking him out, how fresh the beef jerky was.
And he replied "I'm not really sure".

"Well, the package says they are fresh, don't you make them?"

"Oh, no we don't make them, that's the brand name "Fresh" beef jerky.

Monday, March 28, 2011

Taipei Public Transportation

Continuing on my previous post about Taipei, one of the things that really impressed me was the public transportation in Taipei. It is well connected by a very reliable public transportation network. There were no shortage of buses and trains, and they cover almost every part of the city. The buses and trains were clean, fast and on time. The people also take pride in keeping their buses and trains clean. Food and drinks are not allowed in the train. I was sipping on a drink by mistake and a man made sure that I know that I am not supposed to do that. People really care about their city and its public utilities.

I was also impressed by the e-bus system. You can take a look at its website by clicking here. Basically what it is is, you can open the website from your smart phone or notebook, select the bus route and number and it will tell you where exactly the bus is currently on the map and how many minutes it will take to reach your bus stop. I thought this was really handy and good use of technology.

And lastly the Taiwan High Speed Rail. It was so easy to buy tickets, check in and board the train. It was very clean and fast and almost as fast as taking the flight from the North to the South. In fact considering the checking in, security check, waiting, baggage claim, etc the train is faster, more convenient and less hassles. I would certainly prefer taking the train to flying.

In a city so populated, it is still easy and inexpensive to get around. A robust, well maintained and reliable public transportation system surely makes a huge difference in a highly urbanized environment.

Friday, March 18, 2011

Sea shell came alive!!

We were on bed at night in our hotel room and we heard some funny noises. Upon investigation we found out that a couple of our sea shells moved out of the bag and were walking and rolling around. We just happened to pick some live ones by mistake. I took a few close up pictures of them and some videos as well.

The next day we went to the sea side and released those two creatures. There were happy they found the sea once again!

Here's one of the videos I recorded

Wednesday, March 16, 2011

Taipei Downtown

Taipei downtown was very interesting. Taipei is a busy, bustling city but very well organized and clean. The traffic can be a little crazy, but the public transportation there is very advanced and reliable. It's fun to take the bus and train to move around, than drive or ride a moped.

I'm sure going to write more on this city later, but for now, a video that I recorded of the water show in financial district of downtown. Taipei 101 can be seen as well with the I love ROC sign lit up on the top.