z·eeki·sh

tech log on gentoo, linux, and random stuff

restoring startx behavior after upgrading to xorg-server 1.16

leave a comment »

Arch Linux has been imposing an increasing maintenance toll as of late. Many of the changes now feel more like creating solutions so people have problems to work out.

Anyway, after upgrading to xorg-server 1.16, startx stops working, with error messages “cannot open virtual console” and “systemd-logind: failed to get session“. To restore old startx behavior, create a file “/etc/X11/Xwrapper.config” with content

allowed_users = anybody
needs_root_rights = yes

See the man page of “Xwrapper.config” for more information

Written by zsh

July 29, 2014 at 12:27 pm

Posted in /etc

Tagged with

sed one-liner for extracting pictures included in a tex file

leave a comment »

When writing up tex manuscripts, I usually put related data/function plots under the same directory as the tex file, or some sub-dir like ‘figs/’. Often times though, many of them are never actually used in the tex file. while I have no problem with cluttering up my folders with unused plots, it is quite painful when you need to pick out those used plots, for example when tar-balling them to share with a colleague or submit it to some journal. Here is a one-liner to extract a list of used plots in a tex file:

sed -n 's/[^%]*includegraphics[^{]*{\([^}]*\)}.*/\1/p' draft.tex

NB:

  1. draft.tex is the desired tex file from which to extract the list of figures.
  2. The -n tells sed to suppress printing unless instructed to (which will be effected by the tailing /p.
  3. The [^%] will skip plots commented out.

Here is the shell command to generate a tarball containing all necessary files:
tar -cvvzf draft.tgz draft.tex *bbl *bst $(for f in `sed -n 's/[^%]*includegraphics[^{]*{\([^}]*\)}.*/\1/p' draft.tex`; do echo `basename $f .pdf`.pdf; done)

Written by zsh

January 20, 2013 at 11:42 am

Posted in /usr/bin

Tagged with , , ,

actkbd and screen rotation in archlinux

leave a comment »

actkbd is in AUR. I need it so the tablet keys on X220 tablet can serve more use (e.g., differentiate between long and short press, etc.)

In order for the rotation script triggered by actkbd to be able to communicate with X, we need to start actkbd with the DISPLAY=:0 environment variable. The AUR package created the /etc/rc.d/actkbd entry. Just change

[ ! -f $PIDFILE ] && /usr/sbin/actkbd -D -q -p $PIDFILE

to

[ ! -f $PIDFILE ] && DISPLAY=:0 /usr/sbin/actkbd -D -q -p $PIDFILE

Written by zsh

February 20, 2012 at 2:40 pm

Posted in no cat is good cat

Tagged with , , ,

dd-wrt ssh port forwarding quirky

leave a comment »

I guess it is more of a web-gui quirky. Anyway, here is what I desire: I want to move the ssh port of the router itself to say 9999, and forward port 22 to a workstation connected to the router.

What I did, which is wrong:
1) dd-wrt -> services -> services: change port of ssh to 9999
2) dd-wrt -> NAT/QoS -> port forwarding: add port from 22 to workstation-ip:22

What I now have, which is correct thanks to this post, is:
1) dd-wrt -> services -> services: change port of ssh back to 22
2) dd-wrt -> NAT/QoS -> port forwarding: add port from 22 to workstation-ip:22
3) dd-wrt -> administration -> management: change [ssh remote port] to 9999

Written by zsh

February 17, 2012 at 12:27 pm

Wacom Bamboo Create (CTH670) on linux

leave a comment »

Apparently the xf86-input-wacom driver is not enough: one has to manually build the kernel module (for kernel version <= 3.2)

1) get input-wacom driver here: http://sourceforge.net/projects/linuxwacom/files/xf86-input-wacom/input-wacom/
2) unpack and run ./configure. Pay attention to the installation instructions at the end of ./configure output
3) copy kernel modules to /lib/modules/ as instructed.
4) modprobe wacom and enjoy

Written by zsh

February 15, 2012 at 10:53 pm

MKL FATAL ERROR /path/to/libmkl_def.so: undefined symbol: i_free

leave a comment »

I started fooling around with python/scipy with the intention of replacing ruby/gsl. Came across this very weird error.

Minimal script to reproduce: invoke ipython -pylab, then in it,

In [1]: from scipy import *

In [2]: a=zeros(1000); a[:100] = 1; b = fft(a)

In [3]: plot(abs(b))

and ipython spits out the titled error.

Found a solution here: before running ipython,
export LD_PRELOAD=/opt/intel/mkl/10.0.5.025/lib/32/libmkl_core.so

apparently, some symbols are defined in libmkl_core.so instead of libmkl_def.so.

Written by zsh

February 5, 2012 at 1:35 am

Posted in no cat is good cat

Tagged with , , ,

stripping url output from bibtex

leave a comment »

The bibliographical information as supplied by journals usually includes a URL field, and bibtex styles like \bibliographystyle{apsrev} will export the URL field in the resulting .bbl file, very nagging to some of us. One way to get rid of these URL links is to use a customized .bst file, e.g.,

  1. locate apsrev to find where the apsrev.bst file is.
  2. cd to the directory, and invoke grep -v 'format.url output' apsrev.bst > your/manuscript/directory/apsrev-no-url.bst to create a no-url version of the bst file in your manuscript directory (or any other directory in the search path of bibtex).
  3. now, in your manuscript, replace \bibliographystyle{apsrev} with \bibliographystyle{apsrev-no-url}

Written by zsh

January 4, 2012 at 4:19 pm

Posted in /etc

Tagged with , , ,

pdf to gif conversion and optimization

leave a comment »

There have been several occasions that I need to generate some gif animations from a bunch of pdf plots (generated by gnuplot’s tikz terminal), so the following procedure merits documenting. Note that convert is part of ImageMagick, and gifsicle is a gif optimization tool.

  1. Converting pdfs to png:
    for f in *pdf; do convert -verbose -density 150x150 $f `basename $f .pdf`.png; done
  2. combining png to gif (and optimize):
    convert -verbose +dither -layers Optimize -colors 32 -delay 5 -loop 0 -dispose previous *png output.gif
    • if there are too many *png files, it’s probably better to divide and conquerer: assuming png files are frame_000 upto frame_139, then first:
      for i in `seq -f "%02g" 0 13`; do convert -verbose +dither -layer Optimize -delay 5 -loop 0 -dispose previous frame_${f}?.png frame_${f}.gif; done
      then
      convert -verbose frame_??.gif all.gif
    • notice that I’ve dropped the -color 32, b/c in my case it actually increases the resulting file size.
  3. further optimization (YMMV) using gifsicle:
    gifsicle -O3 output.gif -o output_optimized.gif

cf:

http://www.wizards-toolkit.org/discourse-server/viewtopic.php?f=1&t=13339&start=15&sid=10c87c23bbac068a5eb44654da33167f


p.s., a related operation is to combine say every 10th of the pdfs for closeup inspection:

pdfjam frame_??0.pdf --papersize '{12in,9in}' --outfile frames.pdf

pdfjam is a frontend to the latex package "pdfpages". The --papersize I used is the same as the one I had used in gnuplot when generating these plots (set term tikz size 12in,9in ...).

Written by zsh

September 14, 2011 at 12:06 am

armadillo, lapack, and intel’s MKL

with 2 comments

I normally use ruby/gsl for everyday numerics because it’s fast to code and extend, and semantically clear, plus you can do cool things like previewing energy spectrum from within irb by interfacing with the gnuplot module—normally you’d write to a tmp file, switch to gnuplot console, and plot it there.

The problem with rb/gsl is speed. The other day, my boss walked in and compiled his fortran code on my machine. It beat my ruby code hands-down—one would think gsl, being a C library, should be on par with lapack, but apparently it’s not, and it’s not (entirely) ruby’s fault since I rewrote the same stuff in C, using gsl, and it’s still about 4 times slower than my boss’s fortran code using lapack. (I guess partly it’s b/c gsl is using its own blas implementation).

So I want something faster but still with natural semantics—e.g., matrix multiplication should be A*B, not dgremm(...A...B...)—so C++ seems a reasonable place to look at. So far I find armadillo suits my needs quite well. It is a c++ linear algebra library interfacing with lapack/blas.

On gentoo, this is what one needs:

  1. If you have intel cpu, emerge sci-libs/mkl. This is a blas/lapack drop-in replacement from Intel. You need to go to intel’s website and register (free) for a non-commercial usage license. AMD has a similar library. Otherwise, just setup your blas/lapack of choice.
  2. use eselect blas/cblas/lapack list/set to choose mkl as the blas/lapack implementation to use.
  3. now emerge sci-libs/armadillo. It is important to install it after 1) and 2) b/c it will decide what library it’s linking against during compilation time

Now, #include <armadillo> in your cpp code, and use
g++ -O3 -larmadillo your_code.cpp -o your_exe
to compile. You don’t have to use -lblas -llapack as these are already taken care of by -larmadillo (which was done in 3 above, that’s why emerge order is important).

On a Mac OS X (my office workstation), the appropriate way to compile is instead:
g++ -O3 -framework Accelerate your_code.cpp -o your_exe
as per armadillo’s readme file.

I transcribed my ruby/gsl code into c++/armadillo, and on the Mac, it actually is 2 times faster than my boss’s fortran code—since both are using the same underlying blas/lapack implementation, I suppose there’s some unnecessary computation in the fortran code. At any rate, it seems safe to say the c++ overhead is not significant so I’ll happily settle for armadillo for the moment.

Written by zsh

March 31, 2011 at 11:41 pm

Posted in /etc, gentoo

Tagged with , , , ,

latex-beamer presentation on dual display (laptop + projector)

with 3 comments

The latex-beamer class supports a \note{} macro where one can add notes/slide descriptions that can be hidden from the audience.Combined with the \setbeameroption{show notes on secondscreen} option (and the pgfpages package), each page in the resulting pdf file has the presentation slide and the notes slide placed side by side. Then one can set up a dual-display environment—laptop + projector being the scenario I’m interested in—so that the presentation slide will show up on the projector while the notes slide is on the laptop. The restrictions here are

  1. the two displays better have the same resolution

    There is a way around this, described here, where essentially one sets up the projector to just reproduce part of the laptop screen, but I find the resulting image on the projector a bit too fuzzy.

  2. The pdf viewer must be able to span the two displays in its presentation mode. Surprisingly my day-to-day choice of lightweight viewer, evince, doesn’t support this—instead it just spans a single display in its full screen mode. (I’m using xrandr for dual-display setup. more on that later). Luckily acroread behaves in the desired manner (with some caveat. see below)

Here’s the script I use to add a projector to the right of my laptop screen (i.e., right edge of laptop screen identified with left edge of the projector screen):

xrandr --output LVDS1 --mode 1024x768 --primary
# force use 1024x768 mode of the projector
xrandr --output VGA1 --mode 1024x768 --right-of LVDS1 || (xrandr --addmode VGA1 1024x768 && xrandr --output VGA1 --mode 1024x768 --right-of LVDS1)

Three things to note:

  1. The reason why I put the projector on the right is because the window manager I use (awesome) automatically push all windows onto the left-most screen when a second screen is added, and you don’t want all your stuff to go up onto the projector–I’m sure there is a way to overcome this in awesome but I’m just too lazy.
  2. The --primary is also necessary, this tells xrandr to set the laptop screen (LVDS1) as the primary one. Why? Because when going into full screen mode, acroread aligns the top-left corner of your document to the top-left of the primary screen. If your projector ended up becoming the primary screen, your notes will be displayed on the projector instead of your slides (which is pushed outside the visible range).
  3. With the above layout, your beamer document should have notes frames placed on the left hand side, \setbeameroption{show notes on secondscreen=left}

For completeness, here is the script to shut off the projector output:

xrandr --output VGA1 --off
xrandr --output LVDS1 --auto

Written by zsh

March 18, 2011 at 12:51 am