Thursday, September 11, 2014

A Note on JavaScript

JavaScript appears to be a growingly popular choice of programming languages for many things, perhaps, as a result of HTML5 development, a result of being able to run in a sandbox, a result of being able to create closure, and others ... ... I am particularly impressed by BablylonJS as I came across it today.

It is the time for me to create, well, a bookmark for a few JavaScript libraries, frameworks, IDEs, and every other thing about JavaScript that I have come across. I'll keep it updated when I come across something interesting.

WebGL

Server-Side JavaScript

Client-Side Javascript

Tutorials and Examples



Sunday, September 7, 2014

All About Food

This servers as a bookmark for various cooking shows, blogs, books and many others that I like. I will keep updating this post. 

Personality
Recipe Blogs & Sites
Media
Books

Personal Website

Ubuntu 14.04 (Trusty) and VMWare Unity Mode

Unity mode is a nice feature of VMWare's virtualization software. However, you will find that you cannot switch to VMWare Unity mode once you install the most recent release of Ubuntu including Ubuntu 14.04 (Trusty) and its predecessor (Ubuntu 13.10 or Saucy).

It turns out that VMWare does not like Ubuntu's default desktop environment called Ubuntu Unity. It could be confusing that the Ubuntu Unity desktop environment and the VMWare Unity mode share the same word "Unity", and it has created a difficulty  for us who try to find an answer  on the web since depending on what search terms you enter, web searches can give you answers related to both and it becomes a diffcult task to find a solution that may help you.

Since VMWare cannot switch to Unity mode is a result that VMWare does not like Ubuntu's default desktop environment called Ubuntu Unity, the solution becomes to find a Desktop Environment that VMWare can work with.

On Ubuntu 13.10 (Saucy), I found that Gnome 3 works with the VMWare Unity mode. Therefore, the solution is to install Gnome 3 and to use Gnome 3. To install Gnome 3, you may issue command below,
sudo apt-get update; sudo apt-get install gnome-session-fallback

I have been happily running Ubuntu 13.10 (Sauncy) as a guest operating system and using it in VMWare Unity mode for a quite while, well, until I upgrade it to Ubuntu 14.04 (Trusty). What is the problem? I checked the versions of Gnome 3 before and after the upgrade from Ubuntu 13.10 (Sauncy) to Ubuntu 14.04 (Trusty), they are the same,

$ gnome-session --version
gnome-session 3.9.90

I believe that it is still the issue with the Desktop environment that Ubuntu is running -- not VMWare tries not to support such a feature. Then, the task is to find out which desktop environment works with the VMWare Unity mode on Ubuntu 14.04 (Trusty). I found the list of Desktop environments that I may try from this post, 
I did not try all of them. However, I am happily to report that the following Desktop environments that work with VMWare Unity mode on Ubuntu 14.04 (Trusty),

  • Xfce
    To install it. Run
          sudo apt-get install xfce4
      
    or if you want more bells & whitsles, 
          apt-get install xubuntu-desktop
          
  • LXDE
    To install it. Run
          sudo apt-get install lxde
      
    or if you want the full desktop environment,
          apt-get install lubuntu-desktop
          
  • Mate
    To install it. Run
    sudo apt-add-repository ppa:ubuntu-mate-dev/ppa
    sudo apt-add-repository ppa:ubuntu-mate-dev/trusty-mate
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install --no-install-recommends \
                        ubuntu-mate-core ubuntu-mate-desktop
    
    At this point, you can switch to VMware Unity mode. However, the application menu of the VMWare Unity mode is empty. This is the result that the VMware tools at present only recognoizes three desktop environments, Gnome, KDE, and Xfce -- if you run vmware-xdg-detect-de in your Ubuntu guest, you will see that the output of the script is empty. I made one minor change to the script,  and the VMWare Unity mode menu appeared. Below is the diff result on the script before and after the revision.
    diff \
      /usr/bin/vmware-xdg-detect-de \
      $HOME/vmware-tools-distrib/lib/bin32/vmware-xdg-detect-de
    63,67d62
    <   elif `dbus-send --print-reply --dest=org.freedesktop.DBus \
    <       /org/freedesktop/DBus \
    <       org.freedesktop.DBus.GetNameOwner \
    <       string:org.mate.SessionManager > /dev/null 2>&1` ; \
    <       then DE=gnome; # pretent to be gnome
    

    The complete script is at GitHub.
  • GNOME Flashback/Fallback

    As described before, to install it, run,
    sudo apt-get update; sudo apt-get install gnome-session-fallback
        
    Initially, I thought GNOME Flashback/Fallback stopped working with VMware Unity mode on Ubuntu 14.04. However, once I investigated further, I discovered that Ubuntu 14.04 reports the value of environmental variable XDG_CURRENT_DESKTOP as Unity. The solution is still to let vmware-xdg-detect-de return gnome. What I did is shown in this diff result,
    diff /usr/bin/vmware-xdg-detect-de \
         $HOME/vmware-tools-distrib/lib/bin32/vmware-xdg-detect-de
    58,60d57
    < DE=gnome
    < xdgDE=gnome
    

    The complete script using the approach described above (although not identical) is at GitHub. It is worth noting that when I manually set the environmental variable to GNOME in the user profile, e.g., adding the following line to $HOME/.profile, VMware Unity mode remains NOT working. 
    export XDG_CURRENT_DESKTOP=GNOME
    
    It begins to work only after I made the revision to vmware-xdg-detect-de as described above.

    A new problem I have encountered is that once VMware enters the Unity mode, in some of my Ubuntu virtual machines, the application menu is empty -- if you always launch programs from command line, it may not be too much of a problem. A further investigation indicates that this problem only occurs on the Ubuntu virtual machines that are upgraded from previous revision. I reinstalled the gnome-session-flashback and the problem went away. To reinstall the package, do,
    
    sudo apt-get install --reinstall gnome-session-flashback
    

    Just be aware that when you have GNOME Flashback/Fallback installed, you will have two options on the login screen, "GNOME Flashback (compwiz)" and "GNOME Flashback (metacity)". VMware Unity mode only works with the latter. In fact, VMware lists "a modern version of Metacity or KDE" as a prerequist to use the Unity mode on its website.

To conclude, below is what I have tried.


Testing Result of Desktop Environment for VMWare Unity Mode on Ubuntu 14.04 (Trusty)
Desktop EnvironmentDisplay Name in Login ScreenVMWare Unity Mode Works?
Ubuntu UnityUbuntu DefaultNo
GNOME 3GNOMENo
GNOME 3GNOME Flashback (Compwiz)No
GNOME 3GNOME Flashback (Metacity)Yes (See the note on Gnome above and
download vmware-xdg-detect-de)
XfceXfceYes
XfceXUbuntuYes
LXDELXDEYes
LXDELUbuntuYes
MateMateYes (See the note on Mate above and
download vmware-xdg-detect-de)
AwesomeAwesomeNo

However, if you try a different desktop envionment on Ubuntu 14.04 (Trusty) and it works or does not work with the VMWare Unity mode, please share it with me. I will update this post to include your result.


Saturday, September 6, 2014

LaTeX: Embedding All Fonts in PDF

Many publishers are cautions about readers' experience and want to ensure all fonts are embedded in PDF files when you send your final camera-ready PDF files in.

We commonly use LaTeX to produce publication grade PDF files. However, some publishers warn about the use of pdflatex to compile LaTeX files to produce PDF files, suggesting pdflatex is the culprit. Perhaps, the problem is rather not with pdflatex, but with the configuration of pdflatex. My experience indicates that default configuration of most LaTeX distributions has already got the configuration right. However, my experience indicates that regardless I use pdflatex or the combination of latex, dvips, and ps2pdf, I have many occasions that not all fonts are embedded.

The issue is actually not with latex, but with figures generated by some third party tools. For instance, if you use Matlab to save figure as an eps file, for instance, the following Matlab script produces an eps file example_signal.eps showing a cosine signal.

num_periods = 10;

freq = 5;
sampling_interval = 1/100;
signal_length = num_periods * 1 / freq;
t = 1:sampling_interval:signal_length;
y = 10 * cos(2 * pi * freq * t + pi / 4);

plot(t, y);

xlabel('t');
ylabel('y');
set(gcf, 'PaperSize', [5 5*0.618]);
set(gcf, 'PaperPosition', [0 0 5 5*0.618]);
print('-depsc', 'example_signal');

Let us convert the eps file to a PDF file.


ps2pdf example_signal.eps
pdfcrop example_signal.pdf


Now let us verify if the resulting PDF file has had all fonts embedded,


pdffonts ./example_signal.pdf
name       type    encoding  emb sub uni object ID
---------- ------- --------- --- --- --- ---------
Helvetica  Type 1  Custom    no  no  no       8  0

The above shows that font Helvetica is not embedded. How do we make sure all fonts are embedded. You must include as the example shows, 5 switches in the ps2pdf command,


ps2pdf \
       -dPDFSETTINGS=/prepress \
       -dSubsetFonts=true \
       -dEmbedAllFonts=true \
       -dMaxSubsetPct=100 \
       -dCompatibilityLevel=1.4 ./example_signal.eps

pdffonts ./example_signal.pdf
name              type    encoding emb sub uni object ID
----------------- ------- -------- --- --- --- ---------
FHQQIQ+Helvetica  Type 1C Custom   yes yes no       8  0


We now see the font is embedded.

Note the following,
  • You must include the 5 switches in the ps2pdf command. If you miss one, fonts may not be all embedded. 
  • The command has no effect on PDF files, even though you can run ps2pdf against PDF files and no error or warning will be reported.

If you have a PDF file, but not its ps or eps file, you can use the steps below to convert the PDF file to a ps file and then convert the ps file back to a PDF file. The new PDF file will have all the fonts embedded, for instance,


pdf2ps example.pdf
ps2pdf \
       -dPDFSETTINGS=/prepress \
       -dSubsetFonts=true \
       -dEmbedAllFonts=true \
       -dMaxSubsetPct=100 \
       -dCompatibilityLevel=1.4 ./example.ps
That is all.

Friday, September 5, 2014

The Stem Crisis: Shortage or Abundance of STEM Graduates

From time to time, some minor voice on the shortage of  STEM graduates starts attract attention. Contrary to more dominant view that not only does STEM shortage exist, it may also be a crisis in the making, a recent IEEE Spectrum article questions whether such a crisis is real, which got my attention. A debate ensures and the discussion continues.

I would like to document the opinions of both sides that  I come across.  I'll come back to update this post when I come across new articles.

Motion: There is a STEM Crisis

For the Motion

Against the Motion

Neutral







    Monday, September 1, 2014

    Bypassing SIM Card and Motoblur Account Setup on Atrix 4G

    From time to time, I get the job to deal with a Motorola Atrix 4G phone. Yes, they are an old model, but we do have a couple of them. Fresh out-of-box, the phone always asks the user to insert a SIM card and set up a Motoblur account. To bypassing SIM card and Motoblur account setup, I follow the instruction in this post, which is pretty handy. Just a convenient jump for myselt, click the instruction below for the steps,

    And to quote, the steps are,
    1. Power off the phone
    2. While holding the "Volumn Down" key, power up the phone
    3. As it is powering up, the phone pauses the boot process and displays boot option. Press the "Volumn Down" button a few times, until "Boot Android (No BP)" appears
    4. Now press the "Volumn Up" key to choose the boot option. The phone will resume the boot process.
    5. When it finishes the boot process, the phone displays a language drop-down menu. Thelanguage selection screen is for Motoblur account setup -- the phone has bypassed the "No SIM card/Emergency calls only" screen.
    6. Hold the "Menu" key at the language selection screen of the Motorblur account setup until the soft keyboard appears
    7. Then press the "?123, ALT, ABC, e" key sequence twice in a row, then type the key sequence "b l u r o f f". Note that quotation marks are not part of the key sequences.

    Sunday, August 31, 2014

    Avoiding automatic indentation when pasting code into vim

    I am a vi user and use vim almost daily. One issue that has troubled me is that vim automatically inserts indentations to already well-indented text when I paste the text, e.g., bibtex entry, program segments, into vim because I enabled "autoindent". A solution to address the problem is to inform vim that you are about to paste and then vim will simply paste the text as is,

    1. In vim command mode, type
      :set paste

    2. Then, in vim edit mode, paste the text
    3. Finally, in vim command mode, type
      :set nopaste

    The credit goes to this Stackoverflow post.

    To make switch the paste option on or off easier, we may map the commands to a key or a key sequence. For instance, we can define a mapping ",p" to switch the paste option on or off in the vim command mode by adding the following code snippet into the .vimrc file (located at the $HOME directory),

    
    let mapleader = ","
    nmap <silent> <leader>p :set paste!<CR>
     \ <Bar>:echo "Paste: " . strpart("OffOn", 3 * &paste, 3)<CR>
    set nopaste
    

    The "echo" part above displays an indicator to show whether the paste option is on or off.