I started reading "Kotlin in Action", and as I write this, I'm in the second chapter.
Having used Java for years, what worries me a little is whether type inference impairs readability.
Let's say we take the example in the book,
fun max (a : Int, b : Int) = if (a > b) a else b
For someone reading this code, it's not obviously as to what the return type is, unless they read and understand the implementation (the 'if' expression on the right in this case).
Although the return type of the function is optional only for functions with an expression body like the example above, and not with a block body, it's not totally comforting. For instance,
fun compute(a : Int, b : Int) = if (a > b) xyz(a, b) else abc(a, b)
Also, in the first chapter, there's an example regarding automatic typecasting:
if (value is String) {
// value is now typed as String
println value.toUpperCase()
}
In the example above, the reference 'value' gets casted automatically within the body of the 'if' block to String, which is why you can call toUpperCase without casting it to String explicitly. What this means is that whenever I see a variable in any place in the code, I can't keeps its declaration-time-type in mind while reading the code to know what type it is of; instead, I should always rely on the IDE to tell me what exactly it is. This is quite unsettling as well.
Thursday, February 8, 2018
Monday, November 18, 2013
AGN client daemon restart
I use the AT&T network client in my Linux laptop to make VPN connections.
Occasionally, it doesn't connect, and I figured that when it does that, a simple restart of the agnclient daemon fixes the problem.
sudo service agnclientd --full-restart
Occasionally, it doesn't connect, and I figured that when it does that, a simple restart of the agnclient daemon fixes the problem.
sudo service agnclientd --full-restart
Saturday, August 10, 2013
Games and psychology
I like computer games. Not that I play them a lot but they're good if played when in a good mood. And I'll tell you why.
When my mood is good, Angry Birds appear cute and joyful. Temple Run appears a heroic affair and Subway Surfers feels like playing a naughty prank.
But when my mood isn't all that great, all I see in Angry Birds is poor birds getting themselves killed. All I get from Temple Run and Subway Surfers is that you are destined to die - one way or the other. No matter how many coins you collect, no matter how many heroic deeds you pull through, it's only a matter of time before you die a merciless cold death.
Isn't that strange - the exact same game feels vastly different based on your internal state of affairs. The real world is probably similar too. Keep your thoughts clean and joyful and you'll find the world a wonderful place to be in. Keep hatred and sadness inside you and you'll find the whole world conspiring against you.
Well, maybe that's so. God knows.
When my mood is good, Angry Birds appear cute and joyful. Temple Run appears a heroic affair and Subway Surfers feels like playing a naughty prank.
But when my mood isn't all that great, all I see in Angry Birds is poor birds getting themselves killed. All I get from Temple Run and Subway Surfers is that you are destined to die - one way or the other. No matter how many coins you collect, no matter how many heroic deeds you pull through, it's only a matter of time before you die a merciless cold death.
Isn't that strange - the exact same game feels vastly different based on your internal state of affairs. The real world is probably similar too. Keep your thoughts clean and joyful and you'll find the world a wonderful place to be in. Keep hatred and sadness inside you and you'll find the whole world conspiring against you.
Well, maybe that's so. God knows.
Tuesday, August 6, 2013
Fun with DuckDuckGo's RoboDuck
If you haven't heard it yet, duckduckgo is a search engine with an emphasis on privacy. If you're interested, read more of their views here, here, and here.
And today I came across this little chat bot called RoboDuck that they've put up on their community site https://dukgo.com/roboduck. Although there doesn't seem to be any practical use of this RoboDuck thing, one can nevertheless have some some fun with it :-)
(Read it in reverse order. Oldest chat at the bottom, newest on top.)
And today I came across this little chat bot called RoboDuck that they've put up on their community site https://dukgo.com/roboduck. Although there doesn't seem to be any practical use of this RoboDuck thing, one can nevertheless have some some fun with it :-)
(Read it in reverse order. Oldest chat at the bottom, newest on top.)
Monday, July 1, 2013
Tools to keep your javascript clean
Javascript is a special language. You can learn it easily, you can write useful code easily, and more importantly, you can introduce bugs even more easily.
JSLint is a code quality checker that can catch some common bugs in your javascript:
http://www.jslint.com/
A fork of JSLint that can catch fewer bugs, but is more convinient to use if you already have a big buggy code-base:
http://www.jshint.com/
A great site explaining the reasoning behind the errors and warnings flagged by JSLint:
http://jslinterrors.com/
JSLint is a code quality checker that can catch some common bugs in your javascript:
http://www.jslint.com/
A fork of JSLint that can catch fewer bugs, but is more convinient to use if you already have a big buggy code-base:
http://www.jshint.com/
A great site explaining the reasoning behind the errors and warnings flagged by JSLint:
http://jslinterrors.com/
Sunday, March 31, 2013
DB2 Error messages in SquirrelSQL
SquirrelSQL is a great tool for working with databases. However, I had a bit of trouble running queries against DB2 databases. When a query had a syntax problem (or encountered any other error during execution), it would just show me the SQL Error Code, not the human-readable error string.
There's an easy way to fix that:
In the connection alias, add a property that says:
retrieveMessagesFromServerOnGetMessage=true
jdbc:db2://<server>:<port>/<db-name>:retrieveMessagesFromServerOnGetMessage=true;
Excerpt from the DB2 infocenter:
"During a connection to a data server, set the retrieveMessagesFromServerOnGetMessage property to true if you want full message text from an SQLException.getMessage call."
http://pic.dhe.ibm.com/infocenter/db2luw/v10r1/index.jsp
There's an easy way to fix that:
In the connection alias, add a property that says:
retrieveMessagesFromServerOnGetMessage=true
jdbc:db2://<server>:<port>/<db-name>:retrieveMessagesFromServerOnGetMessage=true;
Excerpt from the DB2 infocenter:
"During a connection to a data server, set the retrieveMessagesFromServerOnGetMessage property to true if you want full message text from an SQLException.getMessage call."
http://pic.dhe.ibm.com/infocenter/db2luw/v10r1/index.jsp
Saturday, January 12, 2013
Gorgeous stone carvings
When I was in Tamilnadu last month, I was delighted to see some wonderful stone carvings in the temples there.
Here a sample of what I saw:
Apart from being beautiful from a distance, these stone carvings are a pleasure when observed closely as well. Just look at the beauty here of this stone lion's mane - brilliant!
Here a sample of what I saw:
Apart from being beautiful from a distance, these stone carvings are a pleasure when observed closely as well. Just look at the beauty here of this stone lion's mane - brilliant!
Tuesday, January 8, 2013
AIX find a string in files
To find the string "str" in all files ending with "java" in the current folder (.),
find . -name '*java' -exec grep -i 'str' {} \; -print
Tuesday, January 1, 2013
Cuda warps - link
A good link on warps and occupancy in cuda :
http://developer.download.nvidia.com/CUDA/training/cuda_webinars_WarpsAndOccupancy.pdf
http://developer.download.nvidia.com/CUDA/training/cuda_webinars_WarpsAndOccupancy.pdf
Tuesday, December 11, 2012
top command in AIX
I keep looking up this piece of information repeatedly; hopefully I can find it here easily:
AIX has a command called "topas" that's a good alternative to the Linux "top" command
topas --help
topas -P
AIX has a command called "topas" that's a good alternative to the Linux "top" command
topas --help
topas -P
Saturday, December 1, 2012
I have a new phone - the Samsung Galaxy Note 2
I usually tend to like simplicity - things that are minimalistic, purposeful, and worthwhile.
That's why I stuck to using a good basic phone all these years - first a Nokia 1100 and then a Nokia 1150. A phone is all I needed, and if I could get to buy a John's Phone in India, I would have gladly done so.
With all the news and buzz around smart phones, I kept observing and didn't find anything that would make me buy them in lieu of my basic phone, but finally this Diwali, I got a great product for which I could justify my purchase -- a brand new Samsung Galaxy Note 2.
I have a lot to say about this new purchase of mine. I really, really liked using it over the past couple of weeks. A single blog post would hardly suffice to describe the marvel that it is. For now, I will keep to a simple, short list of reasons that made me buy it.
Firstly, if you were to ask me "which, in my opinion, is a better phone - a Nokia 1150 or a Samsung Galaxy Note 2? ", I would pick the Nokia 1150.
I didn't buy Samsung Galaxy Note 2 because it was a better phone than Nokia 1150, I bought it because it was the best multipurpose personal gadget that I found in the market, and incidentally, it obviated the need for me to keep using the Nokia 1150.
Samsung Galaxy Note 2 is a fantastic, and in my view, currently the best multipurpose personal gadget out in the market, and here are the reasons:
That's why I stuck to using a good basic phone all these years - first a Nokia 1100 and then a Nokia 1150. A phone is all I needed, and if I could get to buy a John's Phone in India, I would have gladly done so.
With all the news and buzz around smart phones, I kept observing and didn't find anything that would make me buy them in lieu of my basic phone, but finally this Diwali, I got a great product for which I could justify my purchase -- a brand new Samsung Galaxy Note 2.
I have a lot to say about this new purchase of mine. I really, really liked using it over the past couple of weeks. A single blog post would hardly suffice to describe the marvel that it is. For now, I will keep to a simple, short list of reasons that made me buy it.
Firstly, if you were to ask me "which, in my opinion, is a better phone - a Nokia 1150 or a Samsung Galaxy Note 2? ", I would pick the Nokia 1150.
I didn't buy Samsung Galaxy Note 2 because it was a better phone than Nokia 1150, I bought it because it was the best multipurpose personal gadget that I found in the market, and incidentally, it obviated the need for me to keep using the Nokia 1150.
A truly "multipurpose personal gadget"
Samsung Galaxy Note 2 is a fantastic, and in my view, currently the best multipurpose personal gadget out in the market, and here are the reasons:
- It has the largest screen that can fit comfortably in my pockets - both of my trousers and of my shirt. A smaller screen would have made reading e-books, browsing web pages, and in general, any interaction with the device an inferior experience, and a larger screen would have made it impracticable to carry it around. It is therefore better than any other phone and better than any other tablet on this count.
- It is not just a content consumption device - it is a marvellous content creation device too. Let me explain this a bit: Most mobile phones and tablets are good for consuming content posted elsewhere -- i.e., they are good for viewing videos, or reading books, or enjoying music, or reading email. There is usually little emphasis on the creation part. Anyone creating anything serious will do so on a full desktop or a laptop, not with a mobile phone. This, however, does not apply to the Samsung Galaxy Note 2, because of its useful stylus, the S-Pen. The S-Pen lets me take notes, draw sketches, take screenshots, annotate pictures, and do a whole lot more. I know of no other phone in the market that has a stylus as good as this.
- It has a good battery life. This is not something that can be taken for granted, especially after I read a lot of scary reviews of inexpensive mobiles and tablets with bizarre battery behaviour.
- It has an easy-to-extend, and open operating system - the Android. I find it particularly easy because I am already very comfortable with Java. Had it been the iOS, Symbian or Windows, I would have had a steep learning curve before being able to customize and extend my gadget.
- It has a lot of sensors on board - Dual cameras, GPS, (and Glonass), Accelerometer, Compass, Gyroscope, much more than many other smart phones I read about. Every physical sensor gives a massive boost to the potential uses of the gadget.
Saturday, September 15, 2012
Secure JAX-WS with Apache CXF (Some links)
Some useful links for my reference, related to securing JAX-WS services when using Apache CXF:
Some background:
If you want to create a JAX-WS web service as standalone Java program (i.e., one that starts with a main(String..) method), there are two approaches:
1. If you can deploy your application on the Sun JVM, you can probably easily use Sun's HTTP server that comes bundled with it.
Something on the lines of:
KeyStore keyStore = KeyStore.getInstance("JKS");
2. Instead, if you want you application to be portable and be able to run on any JVM, one way is to use an alternate JAX-WS implementation, such as Apache CXF.
Doing this would mean the following:
- Download the CXF distribution and add a large number of JARs that it needs to the classpath.
- If SSL and authentication is not needed, a simple one-liner is all that's needed:
http://cxf.apache.org/docs/a-simple-jax-ws-service.html#AsimpleJAX-WSservice-Publishingyourservice
- If SSL is needed, refer to the wsdl_first_https sample in the CXF distrbution, and set up a Spring configuration file to enable SSL on the embedded Jetty that CXF internally uses:
http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/samples/wsdl_first_https
http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/samples/wsdl_first_https/src/main/resources/ServerConfig.xml
And make your Java program use that Spring configuration:
http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/samples/wsdl_first_https/src/main/java/demo/hw_https/server/Server.java
-If basic authentication is desired, add a Jetty handler to that Spring configuration file,
Some links on initializing a SecurityHandler:
http://wiki.eclipse.org/RAP/FAQ#How_can_I_use_Jetty_basic_authentication_in_my_application.3F
http://stackoverflow.com/questions/8056851/basic-authentication-with-embedded-jetty-7-server-and-no-web-xml-file
Miscellaneous references:
http://cxf.apache.org/docs/jetty-configuration.html
http://stackoverflow.com/questions/12423862/using-j2se-endpoint-with-embedded-tomcat
Some background:
If you want to create a JAX-WS web service as standalone Java program (i.e., one that starts with a main(String..) method), there are two approaches:
1. If you can deploy your application on the Sun JVM, you can probably easily use Sun's HTTP server that comes bundled with it.
Something on the lines of:
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load..
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance..
keyManagerFactory.init..
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init..
HttpsServer httpsServer = HttpsServer.create..
httpsServer.setHttpsConfigurator.. (pass the sslContext here)
HttpContext httpContext = httpsServer.createContext..
httpContext.setAuthenticator.. (for example, a BasicAuthenticator)
httpsServer.start();
Endpoint e = Endpoint.create(impl)
and e.publish(httpContext) 2. Instead, if you want you application to be portable and be able to run on any JVM, one way is to use an alternate JAX-WS implementation, such as Apache CXF.
Doing this would mean the following:
- Download the CXF distribution and add a large number of JARs that it needs to the classpath.
- If SSL and authentication is not needed, a simple one-liner is all that's needed:
http://cxf.apache.org/docs/a-simple-jax-ws-service.html#AsimpleJAX-WSservice-Publishingyourservice
- If SSL is needed, refer to the wsdl_first_https sample in the CXF distrbution, and set up a Spring configuration file to enable SSL on the embedded Jetty that CXF internally uses:
http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/samples/wsdl_first_https
http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/samples/wsdl_first_https/src/main/resources/ServerConfig.xml
And make your Java program use that Spring configuration:
http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/samples/wsdl_first_https/src/main/java/demo/hw_https/server/Server.java
-If basic authentication is desired, add a Jetty handler to that Spring configuration file,
<httpj:handlers>
<beans:bean class="org.example.MyLoginHandler">
</beans:bean></httpj:handlers>
where the handler MyLoginHandler extends ConstraintSecurityHandler, and in its constructor, initializes itself.<beans:bean class="org.example.MyLoginHandler">
</beans:bean></httpj:handlers>
Some links on initializing a SecurityHandler:
http://wiki.eclipse.org/RAP/FAQ#How_can_I_use_Jetty_basic_authentication_in_my_application.3F
http://stackoverflow.com/questions/8056851/basic-authentication-with-embedded-jetty-7-server-and-no-web-xml-file
Miscellaneous references:
http://cxf.apache.org/docs/jetty-configuration.html
http://stackoverflow.com/questions/12423862/using-j2se-endpoint-with-embedded-tomcat
Monday, September 3, 2012
Five months of Linux
Back in April earlier this year, I made a decision to switch over from Windows to Linux. And now it's September - probably a good time to write about it.
It was my work Laptop that I decided to migrate to Linux. I use it all day at office for my regular job, and in that sense, it was probably a pretty risky decision.
Nevertheless, IBM, where I work, has good IT support for employees wanting to switch over to Linux. I got a custom Linux distro DVD from them (based on Red Hat), with a good lot of IBM software pre-installed. The installation went pretty smoothly, and I was up and running in a few hours.
Do I miss Windows? Sometimes yes.
But only occasionally.
1. Look and feel
The Windows look and feel is certainly addictive - for someone who has used Windows for years together, it's natural to feel a bit uncomfortable in Linux - and I had anticipated this. Five months down the road, I feel quite happy with the Linux (GNOME) look and feel now.
2. Power management
Windows does a few other things better too - and the one that I realized a little late is its good power management capability. There's a little feature that goes by the name of "switchable graphics" that I got into trouble with when I moved over to Linux.
Basically if your motherboard has an in-built graphics controller and you also have a more feature-rich, but power-hungry discrete graphics controller attached, Windows makes a choice for your as to which one of these graphics controllers to use. If you're watching a movie or playing a game, probably you'd need the discrete controller, and for normal use, the in-built one is good enough.
My Linux, however, just kept using the discrete one all the time - draining out power quickly and heating up like a stove within a few hours of use. The fan control wasn't good either and I was very worried about it in the first few days of my Linux use. Thankfully, there was a way out in the BIOS setting of the motherboard that I could use to turn off the discrete controller altogether, and I sailed out of the problem.
3. Support for hardware devices
More generally, Windows seems to have better support for hardware devices.
- My home printer, a Canon PIXMA, wouldn't work in Linux (there's no driver)
- My phone, a Nokia, can't be connected to Linux (there's no PC suite for Linux)
With Linux, I always need to be ready for trouble every time I attach any hardware - be it a modem, or an internet data card, a camera or whatever. But for me, hardware support is not a very big deal. This is my work PC - I don't "need" to attach any phone, camera or portable printer to it per-se, I just "want" to, at times, and I can adjust to not being able to do so.
And why won't I switch back to Windows?
Well, to be honest, inertia is certainly one of the factors - I don't want to do all the backup/install/restore/get-accustomed-to business all over again. But that's neither the only factor nor the strongest one.
The way I instinctively feel that Windows looks good, and the way I feel that it works with any hardware I might plug in, I "feel" certain things about Linux too. I feel that my Linux is rock solid - I feel that it won't crash. I feel that Linux gives me the power to make my computer work for me.
Windows makes me feel that my computer is a friend of mine. Linux makes me feel that I'm the boss commanding my computer to do what I want.
Now to the details:
And to conclude, at least for now..
Do I like Linux? Well, not the way I'd adore a beautiful sky with a bright sun and a rainbow on the other side. But I do like Linux the way I'd like the cockpit of a supersonic aircraft at thousand miles above the ground, with me inside.
It was my work Laptop that I decided to migrate to Linux. I use it all day at office for my regular job, and in that sense, it was probably a pretty risky decision.
Nevertheless, IBM, where I work, has good IT support for employees wanting to switch over to Linux. I got a custom Linux distro DVD from them (based on Red Hat), with a good lot of IBM software pre-installed. The installation went pretty smoothly, and I was up and running in a few hours.
Do I miss Windows? Sometimes yes.
But only occasionally.
1. Look and feel
The Windows look and feel is certainly addictive - for someone who has used Windows for years together, it's natural to feel a bit uncomfortable in Linux - and I had anticipated this. Five months down the road, I feel quite happy with the Linux (GNOME) look and feel now.
2. Power management
Windows does a few other things better too - and the one that I realized a little late is its good power management capability. There's a little feature that goes by the name of "switchable graphics" that I got into trouble with when I moved over to Linux.
Basically if your motherboard has an in-built graphics controller and you also have a more feature-rich, but power-hungry discrete graphics controller attached, Windows makes a choice for your as to which one of these graphics controllers to use. If you're watching a movie or playing a game, probably you'd need the discrete controller, and for normal use, the in-built one is good enough.
My Linux, however, just kept using the discrete one all the time - draining out power quickly and heating up like a stove within a few hours of use. The fan control wasn't good either and I was very worried about it in the first few days of my Linux use. Thankfully, there was a way out in the BIOS setting of the motherboard that I could use to turn off the discrete controller altogether, and I sailed out of the problem.
3. Support for hardware devices
More generally, Windows seems to have better support for hardware devices.
- My home printer, a Canon PIXMA, wouldn't work in Linux (there's no driver)
- My phone, a Nokia, can't be connected to Linux (there's no PC suite for Linux)
With Linux, I always need to be ready for trouble every time I attach any hardware - be it a modem, or an internet data card, a camera or whatever. But for me, hardware support is not a very big deal. This is my work PC - I don't "need" to attach any phone, camera or portable printer to it per-se, I just "want" to, at times, and I can adjust to not being able to do so.
And why won't I switch back to Windows?
Well, to be honest, inertia is certainly one of the factors - I don't want to do all the backup/install/restore/get-accustomed-to business all over again. But that's neither the only factor nor the strongest one.
The way I instinctively feel that Windows looks good, and the way I feel that it works with any hardware I might plug in, I "feel" certain things about Linux too. I feel that my Linux is rock solid - I feel that it won't crash. I feel that Linux gives me the power to make my computer work for me.
Windows makes me feel that my computer is a friend of mine. Linux makes me feel that I'm the boss commanding my computer to do what I want.
Now to the details:
- I really adore ssh, scp, sftp, gzip, split and other wonderful utilities now. They are far better, faster, and natively integrated here in Linux than PuTTY and other clones that I had to use back there in Windows.
- Software installation and upgrades are a breeze. I found almost anything I needed in the GNOME package manager - from Octave (for data analysis) to Calibre (e-book reader), KColorPaint (much better than the Windows Paint) and many more.
- When building from source, it's almost impossible in Windows - I'd need to struggle with Cygwin and stuff like that. It's a trivial affair now in Linux.
- And I've really got used to the little widgets on my desktop panels - GNote, the GNOME Calc, the system monitor and so on.
- IBM software too work well and feel pretty robust in Linux (I have many of them installed to do my job - Rational Software Architect, WebSphere App Server, DB2, Lotus Symphony, Notes, Sametime, and others).
- I never need to worry about stuff like disk de-fragmentation, long file names, or accidentally deleting something in C:\Windows - (only on a handful of times have I had to switch over to root). Backups are easy too. I just tell Deja Dup to backup up my home folder and I can be sure there's nothing else scattered around all over the place.
And to conclude, at least for now..
Do I like Linux? Well, not the way I'd adore a beautiful sky with a bright sun and a rainbow on the other side. But I do like Linux the way I'd like the cockpit of a supersonic aircraft at thousand miles above the ground, with me inside.
Friday, January 27, 2012
Compiling Meep
Meep is a fantastic electromagnetic field simulator from MIT. [Link:ab-initio.mit.edu]
It runs fine on my Windows XP laptop, but my laptop isn't all that powerful to perform any meaningful simulations reliably. Fortunately I got access to a bigger 64-bit Linux machine that's got 128GB of RAM :) Installing Meep on it was a bit of a pain, though.. as I didn't have administrative access to that system, and finding the right versions of dependencies and compiling them with the right options was tricky.
Here's what finally worked for me:
It runs fine on my Windows XP laptop, but my laptop isn't all that powerful to perform any meaningful simulations reliably. Fortunately I got access to a bigger 64-bit Linux machine that's got 128GB of RAM :) Installing Meep on it was a bit of a pain, though.. as I didn't have administrative access to that system, and finding the right versions of dependencies and compiling them with the right options was tricky.
Here's what finally worked for me:
mkdir --parents /home/kpachar1/meep/local
wget ftp://ftp.gnu.org/gnu/libtool/libtool-1.5.6.tar.gz
gunzip libtool-1.5.6.tar.gz
tar -xf libtool-1.5.6.tar
cd libtool-1.5.6
./configure --prefix=/home/kpachar1/meep/local
make clean
make
make install
cd ..
wget ftp://ftp.gmplib.org/pub/gmp-5.0.3/gmp-5.0.3.tar.bz2
bunzip2 gmp-5.0.3.tar.bz2
tar -xf gmp-5.0.3.tar
cd gmp-5.0.3
export LDFLAGS=-L/home/kpachar1/meep/local/lib
export CPPFLAGS=-I/home/kpachar1/meep/local/include
./configure --prefix=/home/kpachar1/meep/local
make clean
make
make install
cd ..
export LD_LIBRARY_PATH=/home/kpachar1/meep/local/lib
wget ftp://ftp.gnu.org/gnu/guile/guile-1.8.8.tar.gz
gunzip guile-1.8.8.tar.gz
tar -xf guile-1.8.8.tar
cd guile*
export LDFLAGS=-L/home/kpachar1/meep/local/lib
export CPPFLAGS=-I/home/kpachar1/meep/local/include
./configure --prefix=/home/kpachar1/meep/local --with-local-prefix=/home/kpachar1/meep/local
make clean
make
make install
cd ..
export PATH=$PATH:/home/kpachar1/meep/local/bin
wget http://ab-initio.mit.edu/libctl/libctl-3.1.tar.gz
gunzip libctl-3.1.tar.gz
tar -xf libctl-3.1.tar
cd libctl-3.1
export CPPFLAGS=-I/home/kpachar1/meep/local/include
export LDFLAGS=-L/home/kpachar1/meep/local/lib
./configure --prefix=/home/kpachar1/meep/local
make clean
make
make install
cd ..
wget http://www.open-mpi.org/software/ompi/v1.4/downloads/openmpi-1.4.4.tar.bz2
bunzip2 openmpi-1.4.4.tar.bz2
tar -xf openmpi-1.4.4.tar
cd openm*
./configure --prefix=/home/kpachar1/meep/local
make
make install
cd ..
wget http://www.hdfgroup.org/ftp/HDF5/releases/hdf5-1.6/hdf5-1.6.10/src/hdf5-1.6.10.tar.gz
cd hdf5-1.6.10
./configure --prefix=/home/kpachar1/meep/local
make clean
make
make install
cd ..
wget http://ab-initio.mit.edu/h5utils/h5utils-1.12.1.tar.gz
gunzip h5utils-1.12.1.tar.gz
tar -xf h5utils-1.12.1.tar
cd h5utils-1.12.1
export LDFLAGS=-L/home/kpachar1/meep/local/lib
export CPPFLAGS=-I/home/kpachar1/meep/local/include
./configure --prefix=/home/kpachar1/meep/local
make clean
make
make install
cd ..
wget http://ab-initio.mit.edu/meep/meep-1.1.1.tar.gz
gunzip meep-1.1.1.tar.gz
tar -xf meep-1.1.1.tar
cd meep-1.1.1
./configure --prefix=/home/kpachar1/meep/local --with-libctl=/home/kpachar1/meep/local/share/libctl --with-mpi
make clean
make
make install
meep-mpi
cd ..
Tuesday, July 13, 2010
Eclipse RCP product export and ${target.os}
It's a fine day today. My small little Eclipse-RCP app is looking all fine and healthy.
I open my plugin.xml and click on the round, green "Launch an Eclipse application" icon and it works great.
Sometimes I use Run->Run History->and pick the latest one, and again, it works flawlessly.
Cool. Now let's package it up in an EXE.
Here's the problem.
You'd think it's just a matter of creating a product configuration file, right? Just right click on the plugin project, choose New->Product Configuration. Then select "Use a launch configuration" and point it to our trusted, tested, working launch configuration.
Do it, and it won't work. I tried it with Eclipse 3.5 (Galileo) as well as Helios, and it just doesn't work.
You application refuses to start. You look at the logs in the "configuration/" folder and you see cryptic stuff like this:
org.osgi.framework.BundleException: The activator org.eclipse.ui.internal.WorkbenchPlugin for bundle org.eclipse.ui.workbench is invalid
java.lang.NoClassDefFoundError: org.eclipse.swt.SWTError
Well, the SWT jars are there. The Windows-specific ones are there too. I *have* done a Synchronize before export, I did choose to include all dependencies, including the optional ones.
The problem, as it happens to be, is a tiny little thing called the "Program Arguments".
This is what you get by default from the new Product Configuration wizard:

And this says that the product is to be launched on an OS named "${target.os}". I have heard of Windows XP, Linux, AIX, Solaris, but never something claled ${target.os}.
Of course, the launch configuration has the same string and it works fine.. but it gets replaced by the actual value of the OS when it runs. But the poor product configuration doesn't know that and treats it verbatim.
I'm running on Windows XP, not ${target.os}. So it doesn't recognize the target platform. It doesn't recognize the platform-specific SWT JARs, and it fails.
I tired for a minute or so to figure out what the right values for these variables were for Windows XP / J2SE 5.0, but I couldn't get them. Deleting them (blanking out the Program Arguments box completely) worked for me, though. So I won't care about it until I come across a problem with it again.
I open my plugin.xml and click on the round, green "Launch an Eclipse application" icon and it works great.
Sometimes I use Run->Run History->and pick the latest one, and again, it works flawlessly.
Cool. Now let's package it up in an EXE.
Here's the problem.
You'd think it's just a matter of creating a product configuration file, right? Just right click on the plugin project, choose New->Product Configuration. Then select "Use a launch configuration" and point it to our trusted, tested, working launch configuration.
Do it, and it won't work. I tried it with Eclipse 3.5 (Galileo) as well as Helios, and it just doesn't work.
You application refuses to start. You look at the logs in the "configuration/" folder and you see cryptic stuff like this:
org.osgi.framework.BundleException: The activator org.eclipse.ui.internal.WorkbenchPlugin for bundle org.eclipse.ui.workbench is invalid
java.lang.NoClassDefFoundError: org.eclipse.swt.SWTError
Well, the SWT jars are there. The Windows-specific ones are there too. I *have* done a Synchronize before export, I did choose to include all dependencies, including the optional ones.
The problem, as it happens to be, is a tiny little thing called the "Program Arguments".
This is what you get by default from the new Product Configuration wizard:

And this says that the product is to be launched on an OS named "${target.os}". I have heard of Windows XP, Linux, AIX, Solaris, but never something claled ${target.os}.
Of course, the launch configuration has the same string and it works fine.. but it gets replaced by the actual value of the OS when it runs. But the poor product configuration doesn't know that and treats it verbatim.
I'm running on Windows XP, not ${target.os}. So it doesn't recognize the target platform. It doesn't recognize the platform-specific SWT JARs, and it fails.
I tired for a minute or so to figure out what the right values for these variables were for Windows XP / J2SE 5.0, but I couldn't get them. Deleting them (blanking out the Program Arguments box completely) worked for me, though. So I won't care about it until I come across a problem with it again.
Sunday, July 11, 2010
What's wrong with the JSF 2 ui:repeat
The single little thing that's been able to hold my attention repeatedly over the past few weeks in JSF 2 has been the "ui:repeat" tag.
To begin with, it's quite simple. It's so very simple that it's authors probably find it too trivial to explain what it does. This is all you get in its tag library documentation:

Ok. So it's an alternative to c:forEach, or h:dataTable, right? Maybe they just created this tag for some political reasons(if there're two more tags in the same spec and the same impl for the same purpose, you do get the doubt), but that's fine with me as long as it works.
"As long as it works".. hmm... yes.. and that's the tricky part. It seems to be that there are a number of issues with ui:repeat. Most importantly, when you have nested ui:repeats, things start behaving real crazy.
OK. So what if it has bugs? It's an alternative to c:forEach and h:dataTable, right? Let's use c:forEach instead.
And so, when you start using c:forEach, you realize that it's a totally different tag, with a totally different purpose.
Ok. So ditch that c:forEach. Let's see what the bugs with ui:repeat and apply patches ourself.
The first thing - ui:repeat doesn't recognize model updates.
The fix is quite simple. In the process method of UIRepeat, just add a simple check (as suggested by the proposed patch on the bug report):
And the second thing - ui:repeat botches up input fields - checkboxes, textboxes and all sorts of EditableValueHolders in general. That has also been reported.
The fix is pretty simple, though if you are like me, new to JSF, and stuck with it, with no other way out, you'd need to hit your head against the code for anywhere between three to five days before you figure it out.
In the populate method of the SavedState inner class, just change this one line:

The root cause of this second bug is an API design flaw -
The JSF ValueHolder interface has two methods getValue and setValue, but interestingly, they are not complementary. That is, if you use the setValue method and push in some value, you may not get that same value out of the getValue.
Why? Because that's how it has been designed.
Defies conventions and common-sense expectations? Certainly does. Bad API? Definitely.
The method ought to be named setLocalValue, not setValue.
I wonder how these seemingly simple bugs in code and documentation seem to be around for years in such a high quality, high visibility software library.
To begin with, it's quite simple. It's so very simple that it's authors probably find it too trivial to explain what it does. This is all you get in its tag library documentation:

Ok. So it's an alternative to c:forEach, or h:dataTable, right? Maybe they just created this tag for some political reasons(if there're two more tags in the same spec and the same impl for the same purpose, you do get the doubt), but that's fine with me as long as it works.
"As long as it works".. hmm... yes.. and that's the tricky part. It seems to be that there are a number of issues with ui:repeat. Most importantly, when you have nested ui:repeats, things start behaving real crazy.
OK. So what if it has bugs? It's an alternative to c:forEach and h:dataTable, right? Let's use c:forEach instead.
And so, when you start using c:forEach, you realize that it's a totally different tag, with a totally different purpose.
Ok. So ditch that c:forEach. Let's see what the bugs with ui:repeat and apply patches ourself.
The first thing - ui:repeat doesn't recognize model updates.
The fix is quite simple. In the process method of UIRepeat, just add a simple check (as suggested by the proposed patch on the bug report):
if (PhaseId.RENDER_RESPONSE.equals(phase) && !hasErrorMessages(faces)) {
if(isNestedInIterator()){
this.childState = null;
}
}
And the second thing - ui:repeat botches up input fields - checkboxes, textboxes and all sorts of EditableValueHolders in general. That has also been reported.
The fix is pretty simple, though if you are like me, new to JSF, and stuck with it, with no other way out, you'd need to hit your head against the code for anywhere between three to five days before you figure it out.
In the populate method of the SavedState inner class, just change this one line:
this.value = evh.getValue();
to
this.value = evh.getLocalValue();

The root cause of this second bug is an API design flaw -
The JSF ValueHolder interface has two methods getValue and setValue, but interestingly, they are not complementary. That is, if you use the setValue method and push in some value, you may not get that same value out of the getValue.
Why? Because that's how it has been designed.
Defies conventions and common-sense expectations? Certainly does. Bad API? Definitely.
The method ought to be named setLocalValue, not setValue.
I wonder how these seemingly simple bugs in code and documentation seem to be around for years in such a high quality, high visibility software library.
Saturday, June 12, 2010
TinyMCE as a JSF 2 composite component
I was looking for a rich text editor that I could use on a jsf page, but quite surprisingly, there seems to be nothing useful.
So I tried creating one of my own by using TinyMCE.
It wasn't actually very tough to do.. here's what kind-of worked:

First, I downloaded TinyMCE, and then copied in the tinymce_3_3_7\tinymce\jscripts\tiny_mce folder into my WebContent/resources.
Then I created my composite component facelet file, tinymce.xhtml under the resources/editors folder.
The component itself is quite simple. It just includes the TinyMCE javascript in the head of the document, and outputs a simple text area. Configuration for TinyMCE is done in the tinymce_init.js.

In tinymce_init.js, I have:
Then in my view page, I use it like this:
So that stuff gets saved upon AJAX postbacks, I added this to tinymce_init.js:
And here's what I have finally, with everything I need:
- As many rich text editors as I want on a page,
- These editors work nicely with JSF 2, VDL and f:ajax
- These are simple editors - they don't have tens of buttons and options that confuse users
So I tried creating one of my own by using TinyMCE.
It wasn't actually very tough to do.. here's what kind-of worked:

First, I downloaded TinyMCE, and then copied in the tinymce_3_3_7\tinymce\jscripts\tiny_mce folder into my WebContent/resources.
Then I created my composite component facelet file, tinymce.xhtml under the resources/editors folder.
The component itself is quite simple. It just includes the TinyMCE javascript in the head of the document, and outputs a simple text area. Configuration for TinyMCE is done in the tinymce_init.js.

In tinymce_init.js, I have:
tinyMCE.init({
mode : "specific_textareas",
theme : "simple",
debug : true,
editor_selector : "tinymce"
});
Then in my view page, I use it like this:
<h:head />
<h:body>
<h:form id="form">
<h2>Summary:</h2>
<test:tinymce value="#{bean.summary}"/>
<h:panelGrid id="details" layout="block">
<h:commandButton value="Add details..." action="#{bean.showDetails}"
rendered="#{not bean.detailsAdded}">
<f:ajax render="details" />
</h:commandButton>
<h:commandButton value="Remove details" action="#{bean.hideDetails}"
rendered="#{bean.detailsAdded}">
<f:ajax onevent="ajaxAdjust" render="details"/>
</h:commandButton>
<h:panelGrid id="details2" layout="block" rendered="#{bean.detailsAdded}">
<h2>Details:</h2>
<test:tinymce value="#{bean.details}"/>
</h:panelGrid>
<br />
</h:panelGrid>
<h:commandButton value="Save"/>
</h:form>
</h:body>
So that stuff gets saved upon AJAX postbacks, I added this to tinymce_init.js:
ajaxAdjust=function(evt){
if(evt.status=='begin'){
tinyMCE.triggerSave();
}
};
And here's what I have finally, with everything I need:
- As many rich text editors as I want on a page,
- These editors work nicely with JSF 2, VDL and f:ajax
- These are simple editors - they don't have tens of buttons and options that confuse users
Saturday, May 15, 2010
IDs, passwords and emails
I don't know why it happens so often, but it does. You register for a new account on a site, pick a password for yourself and click Submit. Voila! The account is created.
But hey, wait. Did you notice that it just sent you an email with the password in plaintext, just in case you forget it later?
There's nothing more frustrating than realizing in one glance that:
1. Your password is being stored in plaintext on their system.
2. Your password was posted on public insecure internet in plaintext.
3. Your email provider has a copy of that email, with the password in plaintext.
But hey, wait. Did you notice that it just sent you an email with the password in plaintext, just in case you forget it later?
There's nothing more frustrating than realizing in one glance that:
1. Your password is being stored in plaintext on their system.
2. Your password was posted on public insecure internet in plaintext.
3. Your email provider has a copy of that email, with the password in plaintext.
Saturday, April 10, 2010
Making oceans , drop-by-drop
It's amazing how some companies make good money and run profitably.
Take, for example, an advertisement I saw behind an auto-rickshaw today that offers holograms, at 1 paisa per piece. I couldn't believe it - 1 paisa is the selling price of something? I am wondering how much can the seller earn out of this? Assuming that he's selling it at double the cost, it would still get him just 0.5 paisa of profit per hologram. And because it's a company, 50% of that would be taxed. That leaves 0.25 paisa per hologram. Now, if he needs to employ one factory worker for a modest salary of Rs. 5000 per month, just count how many holograms he must make per month?
5000*100/0.25 = 20,00,000 - Twenty lakh holograms! Just to support one factory worker!
I am amazed how this works out. There must be hundreds of people working in that company - many of who would be getting much much more than 5000 Rupees per month. In addition, it needs to invest in all the massive infrastructure and logistics, and advertisements like the one I saw today.
Churning out hundreds of crores of holograms is one thing, but getting sales deals closed for such a massive amount, month on month, every single month, is another astonishing feat that I can't even imagine how it's done.
It's not just with this hologram company. Chocolates that sell for 50 paisa in small retail shops - they have a huge distribution chain to support in addition to being profitable to the manufacturer. Assuming that the retail shopkeeper gets 10 paisa, the middleman gets 10 paisa, and the manufacturer sells it at double the cost price, and pays 50% tax, he gets 80/(2*2) = 20 paisa per chocolate. And it's not at all clear to me as to how you could make crores of children eat your brand of chocolate, each month, which is what you must accomplish to remain profitable.
Fantastic, isn't it? I would love to discover how this works.. maybe some day I'll figure it out.
Take, for example, an advertisement I saw behind an auto-rickshaw today that offers holograms, at 1 paisa per piece. I couldn't believe it - 1 paisa is the selling price of something? I am wondering how much can the seller earn out of this? Assuming that he's selling it at double the cost, it would still get him just 0.5 paisa of profit per hologram. And because it's a company, 50% of that would be taxed. That leaves 0.25 paisa per hologram. Now, if he needs to employ one factory worker for a modest salary of Rs. 5000 per month, just count how many holograms he must make per month?
5000*100/0.25 = 20,00,000 - Twenty lakh holograms! Just to support one factory worker!
I am amazed how this works out. There must be hundreds of people working in that company - many of who would be getting much much more than 5000 Rupees per month. In addition, it needs to invest in all the massive infrastructure and logistics, and advertisements like the one I saw today.
Churning out hundreds of crores of holograms is one thing, but getting sales deals closed for such a massive amount, month on month, every single month, is another astonishing feat that I can't even imagine how it's done.
It's not just with this hologram company. Chocolates that sell for 50 paisa in small retail shops - they have a huge distribution chain to support in addition to being profitable to the manufacturer. Assuming that the retail shopkeeper gets 10 paisa, the middleman gets 10 paisa, and the manufacturer sells it at double the cost price, and pays 50% tax, he gets 80/(2*2) = 20 paisa per chocolate. And it's not at all clear to me as to how you could make crores of children eat your brand of chocolate, each month, which is what you must accomplish to remain profitable.
Fantastic, isn't it? I would love to discover how this works.. maybe some day I'll figure it out.
Friday, April 9, 2010
Agile Agile
No doubt Agile is interesting.
One of the most beautiful arguments Agile makes is that creating a grand plan upfront is not the best thing to do, because such a plan would invariably be based on a limited knowledge of what you're going to be building. That is true - as you progress on the work, you get to know more of it, and there's no point in sticking to a plan that you made when you were in ignorance of this new knowledge.
Now, let's apply the same thing to Agile itself.
Let me explain. Look at the whole thing at one level above all this. You've got a set of people who want to build something. Now you need a process that orchestrates these folks and gets the work done. Is it fair to pick a process out of the blue and apply it to the system and stick to it? You picked the process when you had limited knowledge on how it would behave. As you worked your way forward, you know more about the system, and naturally, it makes no sense to stick to that old process that you picked upfront when you were in ignorance of all this new knowledge of the system.
So, it's OK to begin by saying that let's have two-week iterations, a stakeholder demonstration at the end of the iteration, a retrospective meeting, daily scrums, planning poker, story points, incremental builds, unit tests and all this.
But then, you must *consciously* modify the process, based on your experiences of how it's going. Process changes must not come out of frustration, angry stakeholders, and sev-1 issues. It must be in the form of a proactive meta-process that continuously modifies the process to suit changing circumstances.
If someone says that "here is a standard Agile practice, follow it" - treat him with suspicion. There is really no standard. Agile is for self-motivated, self-organizing, self-improving people. It is not for those lambs that want to be told what to do. Any team that works on a set of imposed standards is a set of lambs - expect nothing heroic from it.
One of the most beautiful arguments Agile makes is that creating a grand plan upfront is not the best thing to do, because such a plan would invariably be based on a limited knowledge of what you're going to be building. That is true - as you progress on the work, you get to know more of it, and there's no point in sticking to a plan that you made when you were in ignorance of this new knowledge.
Now, let's apply the same thing to Agile itself.
Let me explain. Look at the whole thing at one level above all this. You've got a set of people who want to build something. Now you need a process that orchestrates these folks and gets the work done. Is it fair to pick a process out of the blue and apply it to the system and stick to it? You picked the process when you had limited knowledge on how it would behave. As you worked your way forward, you know more about the system, and naturally, it makes no sense to stick to that old process that you picked upfront when you were in ignorance of all this new knowledge of the system.
So, it's OK to begin by saying that let's have two-week iterations, a stakeholder demonstration at the end of the iteration, a retrospective meeting, daily scrums, planning poker, story points, incremental builds, unit tests and all this.
But then, you must *consciously* modify the process, based on your experiences of how it's going. Process changes must not come out of frustration, angry stakeholders, and sev-1 issues. It must be in the form of a proactive meta-process that continuously modifies the process to suit changing circumstances.
If someone says that "here is a standard Agile practice, follow it" - treat him with suspicion. There is really no standard. Agile is for self-motivated, self-organizing, self-improving people. It is not for those lambs that want to be told what to do. Any team that works on a set of imposed standards is a set of lambs - expect nothing heroic from it.
Subscribe to:
Posts (Atom)


