Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

16.9.12

JavaScript rules!

There's a question I often ask myself: What's missing in Linux? In F/OSS world?
I have a list of answers for this question but there's one answer that might surprise you: We miss a general-purpose-easy-to-learn-easy-to-use programming language.
I think this answer might come as surprise to most people while considering the abundance of programming languages around us like Perl, Python, Ruby, PHP and others but I always felt there was something else missing. Looking back at history I would like to take a controversial example for this topic from the commercial world: The VB6 example. Sure it was a horrible horrible language but people actually used it for their every-day use. I used to see it all around - Windows people wrote utilities with it, wrote prototypes and in some cases even entire projects with it (god forbid!). People were happy with it and that's what really matters.

In the distant past I loved PHP so much that I used to have this "silly" idea that PHP should be used everywhere - on server side , on client side (because I used to think JS sucks), for shell scripts and even for GUI applications but my colleagues and friends used to dismiss this idea by saying PHP is good for server side scripting because it was designed for it and that's where it should stay. I guess they were right but the idea that one scripting language can and should be able to do everything was stuck in my mind. I was a good PHP developer but I never really got to know JS as well (and that's too bad) but since than a lot has happened.

JavaScript has got a new life and that's already old news by now! It got to be 1st place on some Language Popularity Ranking Lists and everybody noticed it - MS with their HTML5+JS applications in Windows 8 , Gnome (v3) having their new and shiny Gnome Shell written entirely in JS, QT with their QT Quick, Mozilla used it to extend Firefox in the past and now I have a feeling they will build a new OS around it.

A few months ago I decided that I had my fair share of living under a rock and that I should check out JS seriously. After looking for recommendations I bought "Javascript the good parts" and started using JS for a little web project I'm working on in the background. I decided to use the "full javascript stack". Here are some projects I found very useful and interesting in the past few months:

  • node.js (js in server side, check out npm - the nice package manager)
  • express (js framework to write server side applications)
  • mongodb (schema-less database, JS-like syntax for queries and JSON for results, very cool)
  • backbone.js (popular framework for client side)
  • JQuery (who doesn't know this one?)
  • Twitter Bootstrap (related to CSS but awesome for lazy developers who still like their poorly designed web pages to look good)
I don't know if it's the one language to rule them all (mostly because I was wrong so many times before :-P) but I can tell you one thing: The developers community is big enough, The projects are alive. Lots of ready-to-use components with permissive licenses, lots of support (in stack overflow). bottom line: lots of fun.

24.12.11

Changing text direction and GNOME

 So you are writing RTL text (Hebrew, Arabic, Farsi ..) and sometimes you tend to mix some English words in it. In Windows and QT (after enabling in qtconfig) you have to press both Ctrl and Shift keys (both left or right) if you want to change direction for a single line/paragraph/selected text.

In GNOME you have the fabulous Auto Detection - the direction of your paragraph is set by the first character having strong direction. That's cool and works most of the time but what are you supposed to do when it doesn't work. Have no fear - the amazing RLM and LRM characters come to the rescue. RLM and LRM possess superpowers such as strong direction, invisibility and the ability to claim you're following the standards. All you have to do to use these is simply hit the Home key then Right-click to get the context menu then select "Insert unicode control character" (or simply change your national keyboard layout standard to include RLM/LRM) then you have to pray to Alohim/Allah that you will not change your mind later on and be forced to look for it and try to delete it.

I say we can make editing bidi-text easier in GNOME by creating several text actions bound to keyboard shortcuts to handle it. Here are the few actions I had in mind:

  1. A shortcut to change current line/selected text direction, just like windows Ctrl+shift does but insert RLM/LRM when needed.
  2. A shortcut to delete all control characters in the selected text - To be used when you made a big mess in your text and you want to fix it manually all over again.
  3. A shortcut to encapsulate selected text within RLE/LRE and PDF (Pop Directional formatting).
  4. A shortcut to encapsulate selected text whithin RLO/LRO and PDF.
This will probably have to be implemented by a patch to GNOME (GtkEntry and GtkTextView) adding some signals to preform the actions and binding them to some keyboard shortcuts. I don't think there's a special low-level API that will allow implementation of such actions. But I did look for such.

I found a very limited way in which GNOME's Input Method API can provide basic line direction switcher (No. 1 in the above list) and decided, for the sake of pure experiment to try implementing it. I think it's a ugly hack but it works well and better than nothing for now... I guess. It's not perfect at all: it works only for single lines, It might delete selected text (works great when no text is selected) and it will insert two edit actions into the undo buffer so to undo a switch you will have to hit Ctrl+z twice.

The keyboard shortcut I chose for it is Ctrl+Shift+0 or Ctrl+Shift+9 which resembles the location of RLM/LRM in the new Israeli keyboard standard. Using Ctrl+Shift alone (like in QT and Windows did) is no good because I fear it might be used for layout group selection in some layouts.

The Debian packaging and some of the code is base on the awesome Debian package for gtk-im-libthai so I was able to code and package it in a very short time, relativly... for a project with no real future.


So far I tried it only on Ubuntu 11.10+GNOME3+i368/amd64. Seems to work:

If you would like to try it, it's available in my Ubuntu PPA, package name: gtk3-im-rtl (not 'gtk-im-rtl' which is for GNOME2 and seems to be broken). currently compiled only for Ubuntu Oneiric 11.10 . You may also try to download the source and compile for other distros.
But don't you come crying to me if it broke your desktop.
The Input Method is supposed to become default after installation. If not, you'll have to set it by yourself (right click->select input method).

Happy Hackinukkah!!!
.. and merry christmas!


26.2.07

A patch to fix some Bidi-text issues in Gaim2

It has been 2 years since I reported bug #1121620 to the Gaim Bug Tracker. I expected that someone will resolve it for Gaim 2.0 but the issue was ignored. A friend told me last week that he doesn't like Gaim because of it's bad Hebrew support in MSN Messenger protocol. I decided that this itch just got too itchy to ignore. So, I looked into it during the weekend and realized I know how to fix it, and so I wrote this patch.

This patch doesn't only fix the problem described in bug #1121620 but also resolves the problems with displaying RTL messages on Gaim's IMHtml Widget.

Before my patch MSN conversation used to look like this:


Notice that the direction of the text was automatically (and correctly) detected in the text input field on the bottom. However, the conversation window displays all lines aligned to the left and the text direction is always LTR - therefore RTL text which includes embedded English words (LTR) becomes unreadable because the words are displayed in the wrong order.

The MSN Messenger user will also see the text displayed using the wrong alignment and the wrong direction:

The patch above will fix all these issues. After patching your Gaim, the above conversation will look like this:

And the MSN Messenger user will see the text displayed correctly:


The Code

Writing the patch was a little tricky - some of the code in there may seem like an ugly hack and there's probably a better way of doing some things. But that's the best I could do with my basic knowledge in GTK and Gaim API.

In this patch I implemented the following:

* Added support for [SPAN dir="rtl"] tag in the parser of the IMHtml Widget. (AFAIK this HTML tag is deprecated, but most browsers implement it and it beats coding CSS support)

* Added text direction detection to outgoing messages and send it with the correct SPAN tag.

* Added support for the "RL=1" flag in Messenger protocol implementation, both in sending and receiving messages.

* Fixed some display issues: Insert RLM and RLE Unicode characters to the conversation display according to the expected alignment and direction.

UPDATE:

Now timestamps will show up on the right side:

in the screenshot:
Hebrew alias + English text
Hebrew alias + Hebrew text
English alias + English text
English alias + Hebrew text