Sunday, June 10, 2012

Discovering Ruby-on-Rails

I remember the days I wanted to build something and created couple of websites from scratch using PHP and MySQL. I also remember that my free-time endeavour turning into a full-time struggle and the day everything went south due to an SQL-injection attack (never really thought of website security until that point.) Even at that time I knew about Ruby on Rails, but just because I didn't want to learn yet another language, I didn't pursue it. Recently I had to learn Ruby-on-Rails for a webdesign project and came to realize how stupid I was in the past!

I believe Ruby became famous thanks to Ruby-on-Rails and I can really understand why. Ruby-on-Rails (RoR) is simply wonderful! Including the time for learning the fundamentals of Ruby and RoR, you can create a complete website within a week or two. It requires your database tables to be setup in a particular way, but once these tables are in place, you don't even have to worry about SQL queries anymore. Also avoided are the possibiliy of me creating stupid security holes asking for an SQL-injection attack. I also like the concepts of layout and partials that let me to structure the visual design of a website. RoR is much different than content management systems; while RoR argumentally makes publishing content as easy as a CMS does, it also let you have a complete control over your design.

So if you are planning to build a website, please consider RoR. The best documentation for RoR is found here.

Saturday, June 9, 2012

Discovering Ruby

As far as spripting languages are concerned, I have been a Python guy for a long time. Then my work required me to learn Ruby and it's been a strange experience. It is said that one of the primary concept in Ruby design is the principle of least astonishment. But, in my learning experience, there was no shortage for astonishments. Ruby provides a lot of shorthands to make the programming much more concise and natural language-like and, in my opinion, this also confuses the programmers coming to the Ruby from other languages. For a simple example, I can point out that, in Ruby, return keyword is optional; whatever value returned by the last statement of a method will be the method's return value.

It took me only a few hours to learn Python (still more weeks to master it.) I see Python as the best mixture of C and Java – for example, if you want to open a file in Python, it follows C's style (a simple open() statement, compared to Java's nested stream opening), but for classes like strings, lists, and dictionaries, it favors Java style. If you know C/C++ and Java, learning Python is a breeze. But, learning Ruby reminded me of learning Perl; while it was simple enough, some Ruby-specific syntax kept me puzzled for stretches of time. For example the ||= operator, which is generally used to assign default values.

One problem I had with Python was that it is space-sensitive (or indentation-sensitive.) While it makes Python source codes super-readable, it creates confusion and bugs when you copy-paste stuffs from one area to another. With Ruby, I happily forgo that problem. Ruby also has many other nice features, like blocks. In summary, once you have got used to its rough edges, Ruby will be real sparkly in your hand.

Wednesday, July 29, 2009

Texlipse Plugin

If you are an Eclipse fan and in love with LaTeX, you should try the eclipse plugin Texlipse. It seems to be still in its infancy, but works fine for general needs.
  • Has command completion with Ctrl+space.
  • Can invoke latex command internally to compile the project.
  • Can spawn xdvi for viewing compiled dvi files.
  • Can handle complicated projects with \input and \include commands.
  • Can keep all the temporary files in a separate directory.
Confusing, irritating, and missing features:
  • It does not have a separate perspective. (Still, it doesn't matter, once installed, it enable additional menus when you open a .tex file.)
  • You better compile with the "build automatically" ON. Otherwise, you will be force to do a lot of "clean, build."
  • There is no way to select a text and apply a latex command to it (for example, change the font style to italics or bold.)
  • Auto-format does not work.
  • Working with spell-check is not that intuitive.

Globally Installing LaTeX Style Files

If you want install a LaTeX style file in Ubuntu/Kubuntu globally so that all the users in the system can access it, put it inside a directory (say misc) in /usr/share/texmf-texlive/tex/latex and run the mktexlsr command from a command line. You have to have root privileges for both the above steps.

Sunday, April 26, 2009

Upgrading to Kubuntu 9.04

I have two desktops, one at home and another at office, installed exclusively with Kubuntu. I had them Kubuntu 8.10 (Intrepid) installed and, when Kubuntu 9.04 was released last Thursday (23rd April, 2009), I decided to upgrade my machines (simultaneously) with the new version. And, that's how I ended up wasting nearly two days...!

Upgrading Nightmares

OK, let's clear about one thing: the fault is half mine. But I am still peeved about how the other half made me go into this half. ;-) When I upgrade my machines from 8.04 to 8.10, which was a major upgrade because KDE moved from 3.x to 4.x, I didn't have this much trouble. Now, when I upgrade from 8.10 to 9.04, where KDE just moved from 4.1 to 4.2, things got messed up. I would say the blame is on the switching of package management tool -- from adept-manager to KPackageKit; I don't have an actual proof to support my this claim though.

My machines' software manager informed me on Thursday that there is a version upgrade available, so I asked it to do the upgrade. Both my machines' upgrade manager broke down in the middle of the upgrade saying the repository failed to respond. Everything went wrong from that point.

My Lab Machine
After the upgrade broke down, I restarted the version upgrade. Instead of downloading the remaining packages needed to upgrade the system properly, it immediately went into installing the already downloaded packages. It went fine and asked me to restart the machine after 'completely upgrading' the system. When I did, my machine booted with Kubuntu 8.04 (which was left aside when I installed 8.10)! Again, the update manager informed me of new updates available, so I updated again. The packages that are updated/installed belonged to 9.04! I still hoped that after this everything will be fine. But after considerable amount of time spent on downloading the packages, the system informed me of a dependency problem and the installation crashed again. Confused about what to do now, I chose to do what came first into my mind -- I rebooted the system. Now things got worse and I was left with only a CLI. I tried all my best to recover the system, but I couldn't resolve the dependency issue. After wasting about 8 hours, I used a live CD to reinstall the OS from scratch. I got no problem there.

My Home Machine
Again, after the upgrade broke down, I restarted it and here things were better. The tool started from downloading missing packages and installed all of them; no dependency issues; no booting into old version. But when I rebooted the system, the system refused to load NVIDIA drivers to utilize my video card. Acccording to the OS's guidance, I switched to use a non-NVIDIA (vesa) driver and my xserver booted with 800x600 resolution. I can do nothing to increase the resolution: I couldn't increase the resolution with the vesa driver and I couldn't use any of the supplied NVIDIA drivers (when I activate them, I couldn't start xserver.) As the next step, I downloaded the latest NVIDIA driver from NVIDIA website. When I tried to install it, it asked me to recompile the kernel. But I couldn't get the source code for the loaded kernel! Frustrated, I decided to go with the approach that worked in the lab -- reinstall the OS from scratch. But, at home, even that failed, when the installation terminated with the "grub-install failed on hd0" message! After multiple install attempts have failed, I have almost decided that my hard disk has gone bad. As usual, I "consulted" Google to resolve this problem. By deciphering number of posts in different forums, I decided to try installing grub manually and that finally worked (ha!) After I have created the proper device-map file, I reinstall the system and it smoothly went pass the point where it got struck earlier. A reboot brought my system live without any problem in video. I enabled the NVIDIA driver later (the recommended one) to enjoy all the sweetness of the KDE 4.2 (even though the default driver brings up the video card with proper resolution and color, some desktop effects can be enabled only when a NVIDIA driver is activated.)

I think that I got the "grub-install failed" message, because grub-install conflicted with the grub files with my 8.10 (or is it 8.04?) installation (I didn't format the drive.) Manually launching grub-install corrected the files, after which the installation went smooth. May be I should have done this at the time when the version upgrade complained about loaded kernel not supporting the provided NVIDIA driver. I should have used the upgrade-grub command to rewrite my grub menu.lst file and I might have saved about 6 hours I spent on reinstalling the system from scratch! But who expected an upgrade not to have updated the grub files!

I also suspect that the things got screwed up, because my machines actually had both 8.10 and 8.04 installed earlier. When I upgraded from 8.10 to 9.04, the upgrade removed the 8.10 installation, but, I think, kept the 8.04 (with KDE 3.x) which made things messed up.

So, after all these struggle, everything is fine. Of course I had to reinstall additional software I needed, such as Firefox, LaTex, Java, Eclipse, Acrobat Reader, etc. As far as I am concerned, the verdict is still out on the new package manager. But the trusty apt-get is always there.

Reinstalling Kubuntu Over an Existing Installation

One thing the *Ubuntu distributions lack is a recovery mode in the installation/live CD. Was there one like that, I am pretty certain that I could've saved a lot of time. Now, the only way to "recover" a system seems to install a new system over an existing one, with the risk of loosing all the data except in /home/.

Reinstalling is pretty easy:
  1. Boot with a live CD and start the installation process.
  2. When the partitioning process begins, choose the manual mode
  3. Don't change the partition setup of the disk. Just enter the partitions' mount point as it were earlier. If you don't know, use a shell from the live CD, mount different partitions to see what is inside, and choose the mount point accordingly.
  4. Make sure "format" checkboxes are unchecked at least for the /home partition (or the partition that contain the /home directory
  5. Proceed with the installation and finish it
In this way, you can be sure that the data in your home partition is saved. If you use the same username for the new installation, you can safely login to your old account without any problem with the new OS version. Anyway, just backup your data with live CD just to be extra-confident.

Love the New KDE 4.2

After all these struggle, things are pretty good. I really like the new KDE. Of course, it borrows a lot from both Vista and Mac, but why not? The taking the best of both of these, KDE looks better. I feel that KDE 4.2 is much more stable than KDE 4.1. The plasma looks better and works better (still not 100% though.) Another think I really appreciate is the performance of GTK applications in KDE. Earlier whenever I do 'heavy' browsing (lot of javascripts, images, etc.), firefox used to crash; I had to restart firefox about 10 times a day. Now no crashes; When I used Eclipse, the plasma panel sometimes used to vanish or behave oddly. Now it is not the case. The only issue I still see is that the image libraries are still have to improve a lot. It takes a noticeable amount of time to load big image files (big in terms of either by resolution or file size). It degrades the experience with graphics/photo softwares. I hope the future updates will further improve the quality of KDE. In any case, now I am not thinking about KDE 3.x as a lost lover any more. :-)

Monday, September 15, 2008

The 'tee' Command

Sometimes you don't see an old, good thing, until you really need them.

tee is Linux shell command using which you can redirect a program's output to the screen as the same time dumping it on a file.

Usage:
$ < program> | tee < output_file>

If it is your own program, make sure that it flushes the output time to time if you want to readily see the output on the screen.

Wednesday, August 20, 2008

Boolean AND and OR

Yesterday, at the lab, we went into an argument on the boolean operator precedence. We always talk about precedence in arithmetic operators, but the precedence in boolean operator is hardly a topic of discussion. One of my colleague claimed that logical AND has higher priority than the logical OR; I sided with another saying that they have equal priority. So we ended up writing sample programs (in python) to verify our claims:

if a or b and c:
print "true1"
if a and b or c:
print "true2"

It's embarrassing that we had this doubt at this stage of the academic life (6th year Ph.D.). But the funny thing is that we couldn't test our claims because of how the compiler works. The programing languages don't go into processing the second operant of a OR statement, if the first is "true"; same with a AND statement, if the first operant is "false". I don't want to write the whole story of why this feature makes the tests invalid, but think about it and you will see it.

Ultimately, we ended up looking at the language documentation (which we should've done in the first place!) and found out my other colleague is right - the AND operator do have higher priority than the OR operator.

Nothing new in this story, but I was just surprised to see how couldn't test the priority programmatically.