Blog 1

Random Talk on Random Thoughts

How to Stop Auto Indenting?

| Comments |

After reading this guide, I created a file $HOME/vimfiles/indent/html.vim with only one line.

let b:did_indent = 1

In the past, I would :setlocal noautoident nosmartindent before pasting anything into a Vim buffer. However, as I paste the jQuery code from a website while I was writing a recent post, the code was still wrongly indented.1 After reading the last section of the tip, I now know to use :set paste.


  1. See Cheat in an Online Quiz in Blog 1 for the copied jQuery function. 

Using Xclip

| Comments |

Background

I always use commands for different tasks. Then I need a command line utility for copying command output into clipboard so as to quickly finish typing the command. Luckily, it’s very easy to install xclip on Ubuntu. I believe that on other GNU/Linux distributions, the installation won’t be too difficult.

Although it’s convenient to use xclip, I experienced two problems while using it on *nix GUI.

Problem 1

Suppose that you want to capture the output of a command, and pipe it to another command. However, the output often consists of a trailing newline character. As a result, I sometimes executed commands incorrectly and carelessly. How can one get rid of it?

Problem 2

Before this Wednesday morning, I didn’t know how to use xclip with other options. Therefore, when I wanted to retrieve to contents in the clipboard, the only two ways that I knew were to use the utility with the -o flag to obtain the output, and to use the middle click of the mouse. However, from problem one, I couldn’t chop off the newline character at the end of the clipped text. Moreover, if one only needs part of the text in the clipboard, it would be quite troublesome to pipe the output of xclip -o to other text editing commands like sed and awk. If one can use a keyboard shortcut for pasting text in a terminal emulator like Gnome Terminal (e.g. <C-v>), then one can also use <C-b>, <Alt-d>, etc. For example, if there’re three words in the clipboard, and I only need the last two, then combining the use of these keyboard shortcuts will enable one to type strings quickly and accurately. Is there such a keyboard shortcut?

Solution

I found two Stack Overflow quesitons extremely useful for improving my skills in xclip.

  1. Bash: Strip trailing linebreak from output
  2. Pipe to/from Clipboard

Octopress Search Error

| Comments |

Problem

I used the search box in the navigation bar to search for pages in this blog.

</source> err1

It had been working well, but a month ago, the box searched for webpages other than those in this blog.

</source> err2

How to limit the search to pages within this site only?

International Space Station Attacked by "Virus Epidemics"

| Comments |

In May, the United Space Alliance, which oversees the running of if the ISS in orbit, migrated all the computer systems related to the ISS over to Linux for security, stability and reliability reasons.

That’s why I still use a GNU/Linux desktop despite the myth that it’s difficult to use.1


  1. Refer to “Myth 1: Linux is just for geeks” in Linux vs Other Operating Systems : 7 common myths busted by fossmaniac for details. 

Go Green, Save Green With Linux

| Comments |

I read this article one year ago. Though it’s written six years ago, I still think that the part about M$ Win* is true.

Avoid e-waste by avoiding Windows Vista—a 2007 study by Softchoice Corporation and amplified by Greenpeace stated that "50% of all PCs are below Windows Vista's basic system requirements" and "94% are not ready for Windows Vista Premium edition". A similar study by the British government found that Linux users need to upgrade their hardware only half as often as Windows users.

I hope that there’ll be more GNU/Linux laptops available for sale, so that I don’t have to face strange problems on M$ Win*.1


  1. For example, I can’t set up Octopress on M$ Win* easily, and got some errors described in Testing Octopress and Ruby 2.0 on Windows 7 (1) and (2) 

A Quick Markdown Syntax Error Detection for Writing MathJax Equations in Octopress Posts (1)

| Comments |

Backgroud

I write math in Octopress posts using MathJax.

Problems

I include $\rm \LaTeX$ code for mathematical expressions rendered by MathJax in Markdown source code for Octopress posts. Then I have to adapt the $\rm \LaTeX$ code for kramdown, which is a Markdown parser that converts kramdown code into HTML. For example,

  1. Add a backslash ‘\’ before an underscore \_.1
  2. Use eight backslashes to stand for a newline in displayed math equations.2

For the second item, I realized that by repeated trials.

Regeneration of the contents in this blog takes more than a minute since jekyll needs to process more than 200 pages. Therefore, a quicker way to verify the Markdown syntax helps.

Method

  1. Write the $\rm \LaTeX$ code for the equations.
  2. Use a $\rm \LaTeX$ compiler to ensure that the code for the equations are right.
  3. Use pandoc to convert the $\rm \LaTeX$ code to Markdown.
  4. Use kramdown to convert the Markdown (i.e. kramdown) code to HTML.
  5. Copy and paste the HTML code into the <body> tag of an HTML file.
  6. Add references to MathJax and a local configuration file in the <head> tag in the HTML file.
  7. Use a web browser to preview the results.
  8. Correct the Markdown syntax, and repeat steps 4–7 if necessary, until the contents are correctly displayed.
  9. Copy the kramdown code and paste it under the YAML header in the Markdown source file for an Octopress post.

Therefore, I often excute the following editor commands in Vim.

:" returns the relative path of the file the current buffer
:echo expand('%')
:!kramdown % > %<.html
:sp %<.html

  1. See Mathjax, Kramdown and Octopress by Lucy Park. 

  2. See MathJax and RSS in Blog 1 for details.