The website has moved

Note: the website moved to www.keenformatics.com. You're being redirected.

Thursday, February 18, 2016

How To Make Terminator Behave Like Guake (Ubuntu)

Terminator is a tool to arrange multiple terminals in a single window, structured on a customizable grid.

When I started using Terminator on Ubuntu, I missed two key features that I had with Guake: an hide/show shortcut, and the possibility to hide its icon from the alt-tab list of running applications.

Hide/Show Terminator like Guake

This solution has been proposed on StackOverflow (see references). I will just copy the code with its attributions and some minor changes.

  • Install xdotool and wmctrl:

    sudo apt-get install xdotool wmctrl
  • Create a file /usr/bin/launch_focus_min.sh.

  • Add the following content to the file:

    #!/bin/bash
    #
    # This script does this:
    # launch an app if it isn't launched yet,
    # focus the app if it is launched but not focused,
    # minimize the app if it is focused.
    #
    # by desgua - 2012/04/29
    # modified by olds22 - 2012/09/16
    #  - customized to accept a parameter
    #  - made special exception to get it working with terminator
    
    # First let's check if the needed tools are installed:
    tool1=$(which xdotool)
    tool2=$(which wmctrl)
    
    if [ -z $tool1 ]; then
      echo "Xdotool is needed, do you want to install it now? [Y/n]"
      read a
      if [[ $a == "Y" || $a == "y" || $a = "" ]]; then
        sudo apt-get install xdotool
      else
        echo "Exiting then..."
        exit 1
      fi
    fi
    
    if [ -z $tool2 ]; then
      echo "Wmctrl is needed, do you want to install it now? [Y/n]"
      read a
      if [[ $a == "Y" || $a == "y" || $a = "" ]]; then
        sudo apt-get install wmctrl
      else
        echo "Exiting then..."
        exit 1
      fi
    fi
    
    
    # check if we're trying to use an app that needs a special process name
    # (because it runs multiple processes and/or under a different name)
    app=$1
    if [[ $app == terminator ]]; then
      process_name=usr/bin/terminator
    else
      process_name=$app
    fi
    
    # Check if the app is running (in this case $process_name)
    
    #pid=$(pidof $process_name) # pidof didn't work for terminator
    pid=$(pgrep -f $process_name)
    
    # If it isn't launched, then launch
    
    if [ -z $pid ]; then
      $app
    
    else
    
      # If it is launched then check if it is focused
    
      foc=$(xdotool getactivewindow getwindowpid)
    
      if [[ $pid == $foc ]]; then
    
        # if it is focused, then minimize
        xdotool getactivewindow windowminimize
      else
        # if it isn't focused then get focus
        wmctrl -x -R $app
      fi
    fi
    
    exit 0
    
  • Make the script executable:

    sudo chmod +x /usr/bin/launch_focus_min.sh
  • Assign the script to a keyboard shortcut. You can do it on Ubuntu using the Keyboard settings:

    Keyboard > Shortcuts > Customized Shortcuts

    From there, you can now add the following custom command:

    /usr/bin/launch_focus_min.sh terminator

    Note that the **launch_focus_min.sh** script can be also used with applications other than **terminator**.

Hide Terminator icon from Alt-Tab menu

  • Download CompizConfig Settings Manager and the compiz-plugins-extra package

    sudo apt-get install compizconfig-settings-manager compiz-plugins-extra
  • Open CompizConfig Settings Manager.

  • Click on Manage Windows.

  • Tick the box next to Window Rules to enable them.

  • Click on Window Rules.

  • Fill in the Skip Taskbar and Skip Pager fields with the following:

    (name=terminator) & class=Terminator

    Note - Here is the meaning of the two fields we filled:

    Skip taskbar These windows will not show up on the task bar (the list of buttons you click on to switch between open windows).
    Skip pager These windows will not show up on the desktop pager (the applet you click on to switch to desktops/workspaces/viewports).

Terminator should now disappear from the Alt-Tab menu.


References

Tuesday, July 14, 2015

Sentiment Analysis lexicons and datasets

Last update: Monday, October 19, 2015.

This is a list of some available lexicons and corpora for Sentiment Analysis (also called Opinion Mining). Il will try to keep this list updated as much as possible. Have fun!

Lexicons

Datasets


Lexicons


Datasets

Tuesday, February 18, 2014

Model-Driven approach vs hardcore coding

Model-driven architecture (MDA) essentially represents a different approach to programming and software development, intended to provide an abstract structure in the realization of those tasks that are usually accomplished by (more or less hardcore) manual coding. Ideally, a model driven approach is supposed to provide an easy-to-follow guideline which can improve code reusability while shortening development times. But can it really be thought as a real substitute for old-style coding? I don't think so, yet I think that MDA approach can anyway represent a precious ally for programmers.

First of all, we have to face the fact that asking if a MDA approach can substitute "traditional" programming already represents a misunderstanding. MDA, often combined with Agile approach and diagrams modeling, defines system functionality using a platform-independent model (PIM) using an appropriate domain-specific language (DSL) (see Model-Driven Architecture). So its natural placement structurally preceeds coding. For example, there are thousand (or millions?) of programmers that dauntlessly engage their coding sessions without drawing diagrams and schemas: those braves won't need an MDA approach, which will almost certainly result frustrating for their usual habits. Let's assume they've got their good reasons to choose this type of approach. Typical MDA users, instead, will look for something more complex that can guide them through a long path of decisions and revisions, usually made by different actors in an enterprise context. In general, each of these experts will manage his own models and diagrams, bringing his contribution to a global Unified Process. Executable code implementation will be just one of the many steps on this path, not even the last one. So, MDA and traditional coding are different practices, and they often mirror different needs.

Moreover, differences between traditional coding and MDA approach can also be found when speaking about time scheduling. I won't assert that there's something like a "winner" between the two, since there's not. More precisely, each of the two approaches will guarantee a time saving when used in the appropriate situation. If you're a coder and you want to create a simple blog, or a small site for which you already prepared all needed libraries, using an MDA approach (or even a MDA framework) will probably become an useless and tedious waste of time, unless you want to take advantage of modeling to better understand your application structure. On the contrary, if you're part of a big company, you'll be absolutely facilitated using an MDA approach in an iterative Unified Process, and the whole process will speed up (given that every member of the team knows how to manage his own task).

Moreover, probably the most controversial side of a hypotetical comparison between MDA approach and hardcore programming is that of code generation. Good automated tools can generate source code starting from the models that MDA actors created during Unified Process iteration. But what does this generated code look like? Does it follow shared standards? Do models model every single part of this code, or something is silently invented during generation (breaking coders trust in automated generation)? This is one of the most complicated tasks that a good MDA framework has to carry out. It has to be confortable enough to make its use worthwhile, but it should at the same time provide a way to mix "manual" coding with model generation, in order to allow programmers to customize their source code when they need to.

Finally, MDA frameworks often rely on a myriad of different technologies and frameworks (e.g. Spring MVC, Apache Wicket, Spring WebFlow, Apache Tiles, logging utilities, EJB containers, Web Services technologies, etc.); those technologies are continuously updated, trashed, deprecated and forked, they're often patched when bugs or security issues are discovered, so it's really difficult to keep updated a framework that makes use of tons of them. Even the newest MDA framework runs the risk of becoming outdated in a truly short time. But this can also be interpreted as a strong point for MDA; think about the moment in which one of your business clients asks for a technology update for his application: if your MDA framework is constantly updated, you could be able to generate a new version of the old application simply using its old models and clicking on "generate". But, as far as I know, nobody has already achieved this level of quality (even if I presume we're not so far from it).

In conclusion, I think that a rough comparison between Model-Driven Architecture approach and hardcore coding is often the result of misconceptions about both of them. I don't think that MDA and hardcore coding should be so easily compared without mentioning their relative peculiarities, so, if asked about whether MDA could really be thought as a real substitute for old-style coding, my answer is no, unless we situate "old-stile coding" in an enterprise context (or a complex context in general). Yet, I expect a foreseeable future in which simpler MDA frameworks will help everyday users (even non-coders) to create their own applications with a growing level of accuracy.

Comments and criticisms are more than accepted!

References

Monday, November 4, 2013

How To show Eclipse menu in Ubuntu 13.10 Saucy Salamander

Note: The following solution also applies to Aptana Studio.

The almost new Eclipse Kepler IDE has been released with a new exciting bug for those who use Ubuntu 13.10 (Saucy Salamander).

If you're among those lucky developers, when you'll open your IDE you'll find that Eclipse upper menu is pretty useless, since clicking on menu entries nothing will happen: no submenus will show up as you expected.

So, what to do if Eclipse menu doesn't show up in Ubuntu 13.10? The best solution at the moment (until someone decides to fix this bug) is the following.




N.B.: This method takes for granted that you already created your eclipse.desktop file. If you didn't create it and you don't want to do that at the moment, you can simply run eclipse by console with this command:

$ UBUNTU_MENUPROXY= eclipse
where "eclipse" is the path to your eclipse executable. But this is just the fast way to run eclipse once. If you don't want to remember this command and use it every time you have to run Eclipse, follow the rest of this guide.

Steps!
  1. Open your eclipse.desktop file:
    sudo gedit /usr/share/applications/eclipse.desktop
    or
    sudo gedit ~/.local/share/applications/eclipse.desktop
    (Depending on your configuration.)
  2. Copy these lines in it:
    [Desktop Entry]
    Type=Application
    Name=Eclipse
    Icon=eclipse
    Exec=env UBUNTU_MENUPROXY= eclipse
    Terminal=false
    Categories=Development;IDE;Java;
    
  3. Save the file.

Yes, that's it. Did you expect something harder? Comment complaining is welcome.

If you found this post useful, please share it!

References

Monday, August 26, 2013

How To create a global InitBinder in Spring with @ControllerAdvice

Date formatting could be an annoying problem when dealing with your views. I wrote an article about it when I was facing Json problems (see How To format dates in Json within Spring 3) but, as you may know, even if you don't need to use Json in your views, you'll probably have to face some troubles with date formats.

Sometimes you can avoid all your problems simply using the specific JSTL fmt in your jsp (see references). But what to do if you can't use JSTL in your jsp, or if a simple JSTL won't solve your problems?

Someone suggests to inject an InitBinder in your controller. What an InitBinder does is to grab your data from web request parameters and bind it to your JavaBean objects. So this could be a good solution if you have to deal with different kinds of data inputs in different controllers. But what if you have to always deal, for example, with dates? You could write a specific InitBinder for each of your controllers, but this is not a good procedure if you want to maximize your code efficiency by an accurate modularization (and this should be your aim, since you're using MVC paradigm).

What I suggest you to do is to create something like a single global InitBinder, which will be activated everytime your application needs it, without any controller restriction. There's a really simple way to do so, using Spring @ControllerAdvice annotation. A class annotated with @ControllerAdvice is a class that assists every controller, and it's easily autodetected through Spring classpath scanning.

If this is your case, and you want to create an InitBinder which manages your dates parsing them in (for example) dd/MM/yyyy format, here's what you can do.

The steps!
  1. Create a DateEditor class like this:
    public class DateEditor extends PropertyEditorSupport {
     
     public void setAsText(String value) {
            try {
                setValue(new SimpleDateFormat("dd/MM/yyyy").parse(value));
            } catch(ParseException e) {
                setValue(null);
            }
        }
    
        public String getAsText() {
         String s = "";
         if (getValue() != null) {
       s = new SimpleDateFormat("dd/MM/yyyy").format((Date) getValue());
      }
         return s;
        }
    
  2. Create a class annotated with @ControllerAdvice (I called it GlobalBindingInitializer):
    @ControllerAdvice
    public class GlobalBindingInitializer {
     
     /* Initialize a global InitBinder for dates instead of cloning its code in every Controller */
     
     @InitBinder
     public void binder(WebDataBinder binder) {
      binder.registerCustomEditor(Date.class, new DateEditor());
     }
    }
    
  3. In your Spring MVC configuration file (for example webmvc-config.xml) add the lines that allow Spring to scan the package in which you created your GlobalBindingInitializer class. For example, if you created GlobalBindingInitializer in the org.example.common package:
    <context:component-scan base-package="org.example.common" />
    

There's nothing else to do for your InitBinder date formatter to work. Remember that @ControllerAdvice is an extremely helpful annotation even when you have to handle exceptions, or if you want to create a global accessible @ModelAttribute for your application.

References