Category Archives: tips

Correct/Repeat the last command under Bash

If you often type the wrong command (or repeat the simmilar commends) under bash shell (like me), you may need to read this post:

cp file1.txt /path/to/dst
cp file1.a1 /path/to/dst
cp file1.a2 /path/to/dst

Substitute the first occurrence

How do I replace .txt with a1 and a2 and repeat the last command? The syntax is as follows for quick substitution and repeat the last command, replacing WORD1 with WORD2:

read more

Proxy Firefox through a SSH tunnel

Have you ever wanted to visit sites during the day from a location that denied access to those sites? What you need is the ability to create a secure and encrypted ssh connection to tunnel your browser traffic through. If you have access to a remote machine by way of ssh, you can set up Firefox to visit these sites.

The following method is only tested on Windows XP, with cygwin installed.

LOCAL_PORT: localhost port for ssh tunnel
SERVER_NAME: remote machine

  1. set up firefox proxy
    • preferences –> advanced –> network –> settings
    • choose SOCKS v5
    • manual proxy configurations: SOCKS
      • Host: 127.0.0.1:LOCAL_PORT
      • No Proxy for: localhost, 127.0.0.1
      • leave the rest of entries BLANK
  2. set up firefox DNS
    • open “about:config” page in Firefox
    • search “network.proxy.socks_remote_dns”, set the value to “true”
  3. establish ssh tunnel

ssh -C2qTnN -D LOCAL_PORT username@SERVER_NAME

read more

dpkg: error processing tex-common

Got the problem while installing latex-cjk-chinese

fmtutil-sys failed. Output has been stored in
/tmp/fmtutil.t6EnBlWW
Please include this file if you report a bug.

dpkg: error processing tex-common (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 tex-common
E: Sub-process /usr/bin/dpkg returned an error code (1)

After checking the file fmtutil.t6EnBlWW, I find the problem is

! I can’t find file `loadhyph-zh-latn.tex’. This is due to the inconsistence between texlive 2011 and tex2012. In tex2012, the file is renamed to `loadhyph-zh-latn-pinyin.tex’. Therefore, the solution is
  1. go to /etc/texmf/hyphen.d
  2. change loadhyph-zh-latn.tex to loadhyph-zh-latn-pinyin.tex
  3. reinstall tex-common

read more

Install brat on Apache2

Install brat

download, unzip and run ./install.

Change the webapp location in Apache2

  1. in etc/apache2/sites-avialble, in default add Alias /brat "/home/brat"
  2. restart apache2:
sudo service apache2 reload

MathJax with blogger.com

MathJax in blogger.com is useful when I need to input equation in my blog. This is a instruction and test of using MathJax in blogger.com.

  1. set blogger.com template to “Simple”. “Dynamic Views” seems not working.
  2. edit HTML by adding the following code between <head> and </head>: <script src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' type='text/javascript'/>
  3. type math equation in the blog.

How to set terminal title dynamically to the current working directory?

It is sometimes helpful to set a terminal window title from a script, so that you can put a couple of reminders of how to do things there. The Xfce4-terminal preference tells me it can be done by setting the “Dynamically-set title” position, but never says how to dynamically put text in the title bar.

Using Zsh

As I’m gradually switching to Zsh, this short post explains how to dynamically set pwd, or current working directory, to xfce terminal in Zsh. Actually, it only contains two steps:

  1. open ~/.zshrc
  2. add the following code
case $TERM in
  xterm*)
    precmd () {print -Pn "\e]0;%~\a"}
    ;;
esac

Let me explain this piece of monstrosity a little bit.