June 6th, 2010 | Categories: Linux | Tags: , , ,

Secure Shell or SSH is a network protocol that allows data to be exchanged using a secure channel between two networked devices. It is primarily used to replace the Telnet and other insecure remote shell.

Port forwarding, or tunneling, is a way to forward otherwise insecure TCP traffic through SSH Secure Shell. For example, you can secure POP3, SMTP and HTTP connections.

There are three kinds of port forwarding, local forwarding, remote forwarding and dynamic forwarding, which are illustrated in following sections.

Read more...
June 4th, 2010 | Categories: Emacs | Tags: , , ,

Org-mode is for keeping notes, maintaining TODO lists, doing project planning, and authoring with a fast and effective plain-text system. It is also an excellent markup language from which HTML can be generated. Comparing to other markup such as markdown, org-mode has some advantages that

  1. It can export source code with syntax highlight.
  2. It can embed LaTeX equation snippets and export them to images.
  3. It generates div around text under each header, so it is easy to adjust the left offset of paragraphs in different level.

Org-mode supports exporting to HTML, but it is not convenient to export many HTML files, e.g., for a site. Publishing can help, but it does not meet my requirements. I have many changes should be applied on the generated HTML. For example, in my notes, I added a breadcrumb and sidebar. In this blog, I need to replace the HTML id in post to make them unique. It can be done by adding org-export-html-final-hook, and I do have added one to clean up unnecessary <br>. But it is painful for me to write complex filter in emacs-lisp, I prefer a easy-to-use script language. I also want to automate the publishing using a tool like Makefile. So I turn to Rake.

The Ruby code can be found in my github repository rubylib. I use it to publish blog and notes.

The publishing has two stages. First org files are exported to HTML files in a temporary directory. Then various filters can be added to change the HTML file and result are saved in destination directory.

I export org to HTML by starting a new instance of Emacs, because I don't want the export block my editing work. The export instance starts with only necessary configurations, such as setting up theme and tab width.

Filters are connect like pipes. I can add dynamic content, fancy widgets or just change HTML to make them look better. For example, in BlogFilter, I make all ID unique so two posts in the same page does not have conflict ID. I add class to exported LaTeX images, so I can apply CSS rules to it. I also add a link at the end pointing to the source org file or the post.

The blog publishing is not automatic. I'm working on Ruby script to automate it using WordPress XML-RPC.

source of this post.

May 29th, 2010 | Categories: Algorithm | Tags: ,

@miloyip has published a post recently which motioned the Alias Method to generate a discrete random variable in O(1). After some research, I find out that it is a neat and clever algorithm. Following are some notes of my study on it.

Read more...
October 25th, 2009 | Categories: Linux | Tags: , , ,

After some upgrades on my Arch Linux, my Firefox suddenly raised an error dialog on startup:

http://doitian.com/wp-content/uploads/2009/10/firefox-error-dialog.png

, where the details button showed me:

Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash. See http://projects.gnome.org/gconf/ for information. (Details - 1: Failed to get connection to session: /usr/bin/dbus-launch terminated abnormally without any error message)

Through command ps aux | grep dbus-daemon, I found out that there are many processes started. The problem is that Firefox cannot communicate with dbus-daemon. After goolgling, the communication is established by setting environment variable DBUS_SESSION_BUS_ADDRESS. It is weird that dbus-daemon was started on-demand, but Firefox had not got the address. So I tried to start dbus-daemon myself when I logged into windows manager, and Firefox no longer reported such error.

Because I use SLiM to start the windows manager, I can add following code in .xinitrc to start dbus-daemon and setup the environment variable correctly (via Arch Wiki). Depending on the startup method, these code may need to add to .xsession, .Xclients or other init files.

# D-bus
if which dbus-launch >/dev/null && test -z "$DBUS_SESSION_BUS_ADDRESS"; then
    eval `dbus-launch --sh-syntax --exit-with-session`
fi

Also see a more complicated version written by me here, which store variables in file and avoid starting multiple instances of dubs-daemon.

September 1st, 2009 | Categories: Desktop, Linux | Tags: , , , ,

2009-09-02: Uploaded the config files package clickable-dzen2.tar.bz2, and the complete XMonad config is available on github.

Xmobar and dzen2 are two poplar status panel for XMonad, because they can be hooked into the logHook and display the status of XMonad. But they are not interactively friendly. Although I can use keyboard to perform all the tasks, in very rare cases, I still want to be able to use only one hand and the mouse.

Fortunately, latest version 1 of dzen2 supports mouse action on region. But XMonad does not support client command to invoke windows management command. Two tools wmctrl and xdotool can help to resolve this problem. The former can interact with any EWMH/NetWM compatible X Window Manager, and the latter can simulate keyboard input. So my solution is adding mouse action in dzen2, use wmctrl to switch desktop and xdotool to change layout.

Read more...
This website uses a Hackadelic PlugIn, Hackadelic SEO Table Of Contents 1.7.3.