Thursday, October 16, 2014

Firefox iMacro Add-on Error (0x8000ffff NS_ERROR_UNEXPECTED)

I was running iMacro Add-on for Firefox on a Linux machine. iMacro reported the following error,

Error: NS_ERROR_UNEXPECTED: 
  Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) 
  [nsIPrefBranch.getIntPref], line 6 (Error code: -1001)

I tried the same script on two Linux machines, the same error occurred. The versions of the two cases are as follows,

  • iMacros for Firefox 8.8.2
  • Firefox 33.0
  • Ubuntu 14.04
A few others saw the similar problem, as reported here in Feburary 2014.

To verify the problem exists, you may run the demo script coming from iMaco add-on, such as, Loop-Csv-2-Web.iim by default at $HOME/iMacros/Macros/Demo-Firefox. In my case, running the demo program would yield the same error.

Apparently, no fixes exist. One suggested workaround is to use an old version of Firefix, as indicated in the discussion mentioned above.

We can download old versions of Firefox from here. I tried Firefox 27.0b9. It works fine with the iMacro demo scripts and my scripts.

Since you would probably have another copy of Firefox installed, it is important that you close all existing Firefox window and run the older version of Firefox using its path. In addition, it is also important to check "Never check for updates (not reocmmended:security risk)" from the Preference under the "Advanced" tab; otherwise, the old Firefox would automatically download updates and the updates would be applied when the old Firefox restarts. Below is the list of steps that I performed,

wget https://ftp.mozilla.org/pub/mozilla.org/\
firefox/releases/27.0b9/linux-i686/en-US/firefox-27.0b9.tar.bz2

tar -xjvf firefox-27.0b9.tar.bz2

firefox/firefox -preferences # disable updates

firefox/firefox



Friday, October 3, 2014

Conditionally Processing LaTeX Documents

Sometimes one may wish to process a LaTeX document based on a condition. For instance, one may wish to conditional process a resume written in LaTeX depending where she is sending the document, i.e., she may wish to expand certain sections, shrink certain sections, or exclude certain sections, in which way, she does not need to maintain multiple different documents that share significant amount of content.

We can use LaTex ifthen package to achieve the purpose. An example is given in this post.

However, some (this and this) suggests that the package is obsolete and we should use the etoolbox package.

I have two examples that use the ifthen package and the etoolbox package, respectively. The complete examples are in Github. I tested the examples on a Linux machine.

In the first example, we use  the etoolbox package and create a "toggle" file (toggle.tex) in the Makefile

ex_cond_1_long.pdf: ex_cond_1.tex
 [ ! -f toggle.tex ] || rm -f toggle.tex
 echo "\\\\toggletrue{long}" > toggle.tex
 pdflatex -jobname ex_cond_1_long ex_cond_1.tex
 
ex_cond_1_short.pdf: ex_cond_1.tex
 [ ! -f toggle.tex ] || rm -f toggle.tex
 echo "\\\\togglefalse{long}" > toggle.tex
 pdflatex -jobname ex_cond_1_short ex_cond_1.tex

The content of toggle.tex is now either,

\toggletrue{long}
or

\togglefalse{long}
Then, in the LaTex file (ex_cond_1.tex), one of two files (long.tex or short.tex) will be conditionally included,

\documentclass[11pt, letterpaper]{article}
\usepackage{etoolbox}
\newtoggle{long}

\input{toggle.tex}

\iftoggle{long}{
    \input{long.tex}
}{
    \input{short.tex}
}

The second example uses the ifthen packag. We demonstrate that we can pass a value from the command line using jobname as shown in the Makefile,

ex_cond_2_long.pdf: ex_cond_2.tex
 pdflatex -jobname ex_cond_2_long ex_cond_2.tex

ex_cond_2_short.pdf: ex_cond_2.tex
 pdflatex -jobname ex_cond_2_short ex_cond_2.tex

Based on whether the jobname is ex_cond_2_long or ex_cond_2_short, one of two files (long.tex or short.tex) will be conditionally included,

\ifthenelse{\equal{\detokenize{ex_cond_2_long}}{\jobname}}{
    \input{long.tex}
}{
    \input{short.tex}
}




Querying Package Status in Linux Systems

I am interested in querying the status of packages on Linux systems. Of course, you can query the status using a number of GUI applications, such as, the "Synaptic Package Manager" on Ubuntu Linux and "GNOME Software" on Federa Linux. However, I am more interested a command line approach.

For Linux systems using APT, such as, Ubuntu Linux, we can use the utilities that comes with APT, for instance, use dpkg-query, as pointed out in this post. In addition, this post gives a few more elaborated queries.

Here are a few examples.
  • To query if a package is installed, i.e, to report status of specified package,

    
    $ dpkg-query -s gnome-shell
    dpkg-query: package 'gnome-shell' is not installed and no information is available
    ......
    

    
    $ dpkg -s gnome-session-flashback
    Package: gnome-session-flashback
    Status: install ok installed
    ......
     
  • To List packages matching given pattern,
    
    $ dpkg-query -l gnome-shell
    Desired=Unknown/Install/Remove/Purge/Hold
    | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
    |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
    ||/ Name           Version      Architecture Description
    +++-==============-============-============-=================================
    un  gnome-shell    <none>       <none>       (no description available)
    
    
    $ dpkg-query -l gnome-session-flashback
    Desired=Unknown/Install/Remove/Purge/Hold
    | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
    |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
    ||/ Name           Version      Architecture Description
    +++-==============-============-============-=================================
    ii  gnome-session- 1:3.8.0-1ubu all          GNOME Session Manager - GNOME Fla
    
    
    $ dpkg-query -l gnome*
    Desired=Unknown/Install/Remove/Purge/Hold
    | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
    |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
    ||/ Name           Version      Architecture Description
    +++-==============-============-============-=================================
    un  gnome          <none>       <none>       (no description available)
    ii  gnome-accessib 3.10.0-1ubun all          Accessibility themes for the GNOM
    ii  gnome-applets  3.5.92-0ubun i386         Various applets for the GNOME pan
    ......
    
For Linux systems using RPM, such as, Fedora Linux, we can use yum and rpm. These two pages, on yum and on rpm respectively provide a few good examples of the two.

Thursday, October 2, 2014

Wildcard Targets in a Makefile (Pattern Rules)

You may use "Wildcard" targets in GNU makefile. In GNU make, this is called Pattern Rules. I find this post is very helpful.  For those who do not  have the patience to read the documentation of GNU Make or to jump to the post, here is a few examples that serves as a summary.

To apply a rule to compile any C++ files, we can write a rule as follows,

CPP=g++
CLFAGS=-Wall

%.o:%.cpp
       $(CPP) $(CFLAGS) $< -o $@

To apply to rule to convert any LaTeX files to dvi files, any dvi files to PostScript files, and then any PostScript files to PDF files, we may write a set of rules as follows,

%.pdf: %.ps
 ps2pdf \
              -dPDFSETTINGS=/prepress \
              -dSubsetFonts=true \
              -dEmbedAllFonts=true \
              -dMaxSubsetPct=100 \
              -dCompatibilityLevel=1.4 $<

%.ps: %.dvi
       dvips -t letter $<

 
%.dvi: %.tex
       latex $<