Saturday, June 27, 2015

Comming Back

Yup, I said I would not do it, but I did. Stopped writing posts here for a while, and now I cannot remember what was my Human Computation idea to improve web searching. Here is a really old post I started to write about it.

Human Computation

Human Computation (HC) is a relatively new area of computer science which studies how to harness the combined power of humans and computers to solve problems that would be impossible for either to solve alone.

Luis Von Ahn, one of the pioneers of this research area, harnessed human brain power of millions of users over the internet for free to complete in less than two years (using HC projects such as Captcha, ReCaptcha, and WGAP) monumental tasks such as labeling all images over the internet, or digitize all the books of the New York Times archive.

Currently, Von Ahn and his team are working on Duolingo, a site to help people learn different languages over the internet for free. The final goal of this proyect is to translate all the content over the internet into several languages. His first goal is to translate all english content of wikipedia to several languages in a few months.

As you can notice, I've been following Von Ahn project development, as I believe that Human Computation is the answer for a lot of current open problems in computer science. Regarding this I have been thinking about a project to create a method to improve the search over the internet.
...

Thursday, February 21, 2013

Extended pattern matching in Bash

While writing scripts in Bash I have found myself needing a more expressive pattern matching for filename expansion, than just the usual "*, ?" and "[]" characters.

When I was looking for a way to accomplish what I wanted to do, I found out that Bash actually contains more advanced pattern matching capabilities, as well as several other interesting features that come disabled by default in most Linux distributions.

The shopt command allows us to query the current status and enable / disable Bash optional behaviours. To manage the extended matching operators, we need to enable the extglob option.

With no options, the shopt command retrieves the current status of the provided Bash option:

$ shopt extglob
extglob        off

Use -s to enable the Bash option you are interested in:

$ shopt -s extglob
$ shopt extglob
extglob        on

Now you can use the extended pattern matching operators, as explained in the Bash reference manual.

References

Thursday, September 27, 2012

Globally modifying the PATH variable

I have several scripts I've wrote through time to automatize my daily tasks (recreate the Arch mirror list, rename downloaded PDFs to comply with a personal format, change the current keyboard layout, etc.).

For some time I executed the scripts using its path, as I used them no more than one time per day. Now that I am using some of those scripts very frequently, I decided to add them permanently to my PATH environment variable.

To accomplish this, I used Bash's (my initial shell) /etc/profile mechanism to globally modify the PATH variable. In Arch Linux (and some other Linux flavors), the default /etc/profile script calls all the scripts contained in /ets/profile.d/, so I just added a script there that does what I need.

#!/bin/bash
#
# adding personal scripts directory to path
#
PATH=$PATH:/home/my-user-name/scripts
export PATH

Finally, to keep this script in my home directory, I added a soft link to profile.d directory, instead of actually place the script there.

ln -s /etc/profile.d/personal_scripts.sh /home/my-user-name/personal_scripts.sh

Tuesday, September 18, 2012

Internal browser issue in Eclipse Linux-GTK 3.7.2

After installing Eclipse 3.7.2 (Indigo SR2 release) on my Arch x86_64 + Xfce box, I was not able to use the internal web browser. I tried with several Eclipse bundles (C/C++, Java, JEE, and Classic) with the same result.

It turns out that Eclipse Framework is built upon SWT (which is an open source widget toolkit for java), and its internal browser is built using SWT's Browser Widget. To provide a multi platform high-level web browser layer, the browser widget can use different web browser engines as its underlying renderer. In the case of Eclipse Linux-GTK version, the supported browser engines are XULRunner (a library that allows Mozilla technologies to be embedded in other apps), and WebKitGTK+ (a GTK wrapper of the WebKit browser engine). If you installed Eclipse (regarding of which specific bundle) by downloading it from Eclipse's site, it is probable that you will need to install one of the browser engines supported by Eclipse as well.

After trying with every single library mentioned in the SWT Documentation, I found this bug report and finally was able to solve the problem. The thing is that, in the latest versions of WebKitGTK+, the libraries changed their name from libwebkit* to libwebkitgtk* and for some reason, SWT Browser widget for Eclipse 3.7.2 was not updated to search for the new names. By adding a symbolic link as shown below, this issue can be solved.

#ls -l /usr/lib/libweb*

lrwxrwxrwx 1 root root       26 Aug 31 00:23 /usr/lib/libwebkitgtk-1.0.so -> libwebkitgtk-1.0.so.0.13.4
lrwxrwxrwx 1 root root       26 Aug 31 00:23 /usr/lib/libwebkitgtk-1.0.so.0 -> libwebkitgtk-1.0.so.0.13.4
-rwxr-xr-x 1 root root 24632360 Aug 31 00:24 /usr/lib/libwebkitgtk-1.0.so.0.13.4

#sudo ln -s /usr/lib/libwebkitgtk-1.0.so.0.13.4 /usr/lib/libwebkit-1.0.so.2


P.S.
I decided not to use XULRunner because of its size and dependencies (in Arch repositories) are larger than the ones of WebKitGTK+.

Update 1.
I have recently tested Eclipse Juno and this issue is now fixed. You just need to tell SWT that you want to use webkit as you default native renderer by adding -Dorg.eclipse.swt.browser.DefaultType=webkit to your eclipse.ini file (more details in SWT's documentation).

Update 2 (Jun 27th, 2015).
As to Eclipse Mars, no extra configuration needed. Webkit is the default native renderer if none is explicitly specified (again, more details can be found in SWT's documentation).

Monday, September 17, 2012

A script to switch the current xkb layout

I recently spent some time setting up a keyboard layout switcher for my Xfce installation. In this post I will share a summary of the main available options I found during the research I did, and the solution I ended up using based on my particular needs.

Requirements

I have an Arch x86_64 + Xfce installed as a guest VM in a Virtualbox on a Windows 7 host. I constantly write documents in Spanish and English on the Linux VM, so I wanted to have a keyboard shortcut to change from 'us' to 'latam' layouts in Xfce.

Very occasionally I also write content in Japanese but, as that content is usually written for web pages or chat conversations, and I very rarely use web browsers or IM apps from the Linux VM, I use the input manager that comes with Windows for this. In other words, I decided not to use an Input Method on my Xfce installation.

Main options

X server configuration file
Manually set the value on the X server configuration file (/etc/X11/xorg.conf) to the desired keyboard layout, as shown in the below example:

...
Option “XkbLayout” “latam”
...

WM / DM integrated app
I am putting here just the apps I tested because they have small print, and are no KDE dependant. These are personal requirements I set up to all the applications I use.
  1. xfce4-xkb-plugin is mentioned in Xfce's FAQ. It is a Xfce-panel plugin that adds an icon to the tray icon area, and allows you to see and change the currently keyboard layout.
    I installed the plugin, but was never able to make it work (it crashed the first time I tried to change the layout, and didn't show up again afterwards).
  2. fbxkb is recommended in Xfce's site. It also shows an icon to the tray icon area, and allows you to see and change the currently keyboard layout. Up to four configurations are allowed (due to X keyboard extension protocol limitations).
    I used it for a while and detected some issues. I find LibreOffice and Lyx sometimes not grabbing the layout change properly (they ignored 'ñ', and á, é, í, ó, ú were displayed as ´a, ´e, ´i, ´o, ´u, respectively). Also, the layout change never worked with Tilda (UTF numeric codes were displayed instead of accents and tildes).
  3. xxkb is a highly configurable layout switcher. It can be used via a window on a tray icon area, or via a small icon on the border of every window showing the current per app layout.
    I wasn't able to use this app because I didn't want to spend much time learning about all the required configuration options (it requires you to specify even the geometry of the main window at the X level). Further, some of the running modes (as the window border one) are not guaranteed to work on all window managers.
setxkbmap
It allows to change the keyboard layout from the command line. It also allows to query the X keyboard extension to get information about the current configuration. After changing the current layout using this command, I tested several desktop and command applications and found no issues.

Selected solution

I ignored the X server file option as I did not want to edit any configuration file (and restart the X server) every time I needed to change the keyboard layout. I also discarded the only WM/DM app I could setup to work (fbxkb) because of its issues didn't let me work fluently.

I ended up writing a very simple script to toggle the current xkb layout between 'us' and 'latam' using setxkbmap, and set it up as a custom keyboard shortcut using Xfce's settings editor.

#!/bin/bash
#

if `setxkbmap -query | grep us > /dev/null`
then
    setxkbmap latam
else
    setxkbmap us
fi
The script was named toggle-xkb and then added to the PATH env variable