2014-01-11

Migration to WordPress

I tried finding a way to blog using Vim, and blogger.vim is what I've found. I've tried this plugin but it doesn't work for my computer. Without Vim, writing code is painful for me. Read the authors' last Blogger post, which was, ironically, about his switch to WordPress, I followed his footstep.

2014-01-10

Compilation of Ruby's Source Code on Ubuntu

Oliver's guide has listed the packages on which Ruby depends. Following strictly to the guide, you should start working with the programming language, instead of wasting time to read this article.
Goal: You need to compile Ruby for whatever reasons.
Background: You've read Oliver's guide. However, your goal does not match with those in Oliver's guide. Therefore, you don't need to do all the things in the guide and start to skim through the text and to scan for commands useful to you. (This is an essential skill to survive in *nix. [1])
Problem: You've found someuseful commands, and tried working out their dependencies. Nonetheless, you missed out some important commands and thus the dependencies were wrong. Unfortunately, you're unaware of such careless mistake and continued the process, before being stopped by the compiler's error message.
In this case, you found the following commands useful.
$ curl
# Substitute [version-number] with that of your downloaded archive.
# If you're NOT sure, use `ls' to list the files inside your folder.
$ tar -xvzf ruby-[version-number].tar.gz
$ cd ruby-[version-number]
$ make
Therefore, you ran all of these commands. Expecting to get things done and to proceed to the next step, you got an error message from the compiler.
Trial: Using a part of the compiler's error message as the query string a search engine, you get some other web pages on the same or similar topics. If you could find blog entries like this some, they might have links to other similar web pages, so you've got even more to read.
I've found DiStasio's article, which contains a hyperlink to Ladd's essay. I tried issuing the following commands accroding to the instructions there.
# Suppose that the current working directory is the same as the one in the above command list.
# If you're NOT sure, use `pwd' to check it.
$ cd ext/openssl
$ make
$ sudo make reinstall # I'd installed the wrong version of Ruby.
Lacking patience to read the blogs, knowledge of using makefiles and experience of compiling softwares from their source code, I don't know how to uninstall the wrong version of Ruby. Are there any make uninstall command?
I tried searching for reinstall and uninstall in the makefile, and failed to find any. Then, I realised that using search engines to answer my questions was inefficient. Reading the official manual of Make wouldn't be effective. Thus, without knowing the truth, I just try the last line of the above list of commands.
The make reinstall command successfully triggered a reinstallation of Ruby, but after running the command, I still received complaints form the compiler. Having no idea on the process, I did the same thing again: copied a part of the message and googled it, and ended up with further more pages to read. The amount of tab pages in my current browser window is too high and this stopped me from opening more web pages on Ruby compilation errors on Google's search result in a new tab.
It took me some time to find out that I overlooked the command below
$ sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core python-software-properties
In Oliver's guide, the above command is right aobve those commands for compiling and installing Ruby. Therefore, I installed them, and tried rebuilding Ruby by running make and sudo make reinstall in my ruby-[version-number]. (i.e. my Ruby source folder) It failed again. Without changing the current working directory directory in the above command list, I did the following because of Ladd's web page.
$ make
$ sudo make reinstall
But it failed again. Maybe I need to go back to ruby-[version-number], recompile the source code and reinstall Ruby again. So using the same current working directory as the one in the above command list, I did the following thing.
$ cd ../.. # For changing the current working directory to `ruby-[version-number]'.
$ make
$ sudo make reinstall
Things still went wrong! I remembered the make clean command, so without changing the current working directory, I ran the following commands.
$ make clean
$ make
$ sudo make reinstall
Remark: With the command dkpg -l | grep ruby, I realised that make clean doesn't uninstall Ruby. It just deletes all compiled files in ruby-[version-number].
It still wouldn't compile with the OpenSSL feature. However, some features that had failed to compile before I had run the command make clean could be compiled.
This inspired me to run the following commands.
$ cd ext/openssl
$ make clean
$ make
$ sudo make reinstall
However, I still got errors. There was a problem in getting the file ossl.o work. (I've forgotten the exact name of that file, and I couldn't find web pages about the same error.) I ignored the message and ran the following commands.
$ cd ../..
$ make clean
$ make
$ sudo make reinstall
But it still didn't go right. After running the commands make and make clean for a number of times, I eventually worked out a solution for my problem. Solution:
  1. Run the command make clean in both the ruby-[version-number] and ruby-[version-number]/ext/openssl directories.
  2. Run make in ruby-[version-number] to compile the source code.
    Some errors like "Failed to compile gdbm" will come out.
    It depends on your needs. Having no clue on what gdbm is, I just proceed to the reinstallation of Ruby.
  3. Run the command sudo make reinstall in ruby-[version-number].
    Then the command gem install bundle in Oliver's guide should work.
Lessons learnt:
  1. Always figure out the dependencies of a package.
  2. Be careful and patient while reading instructions on commands.
  3. Always clear all compiled files before any recompilation.

Reference:
[1]: http://user.frdm.info/ckhung/a/c013.php

2014-01-09

Stop Using Mic**soft Word!

I've found a great post in Charlie's Diary showing reasons that "Why M$ W**d must Die". So I'm going to provide a link to a passage on Coding 2 Learn that explains why M$ W**d is still dominant these days. The whole passage is long, but is worth spending time to read. The relevant section of the passage is Schools. From Cambridge's $\rm \LaTeX$ Advocacy page, we can find Taylor's article titled What has WYSIWYG done to us?. I embed an iframe for your reference.


The HTML code for embedding the PDF document in an iframe is simple.
<iframe height="1125px" src="http://www.ntg.nl/doc/taylor/wysiwyg.pdf" width="100%"></iframe>
However, suppose you have several A4 size PDF documents to upload, and you want to use the same size for the iframes. Then you'll seek a better solution using the concept of class in CSS.

Write Blog Offline!

When I'm writing blogs using the Blogger's online editor, I found that it's slow since the Vim's keyboard shortcuts can't be used. What's worse, Blogger often threw me Error 503. I regret wasting so much time on this ineffective blogging process.

Example of an error experienced by user on Blogger.
Link for effective blogging:
  1. Susan Gunelius' Top 5 Reasons to Use an Offline Blog Editor
Just one will do. Then it'll be good to have some physical exercises for the coordination of our eyes, brain and hand. I've learnt this from my teacher.

2014-01-08

Testing Online Code Syntax Highlighters for Blogs (6): Multilingual Source Code Display in Web Pages

One of my earlier posts suggests that SyntaxHighlight supports only one language in a pre tag without proof. Before embedding a source code list to show this, I'll make more assertions and then verify them.
highlight.js has the support, while google-source-prettify doesn't.
For example, you want to attach the following Matlab code to your blog entry.
SyntaxHighlight doesn't have the Matlab support. For highlight.js, here's the result.
function [rr_array] = nest_fun(x,a)
%function to find sets of polynormials.
% a: set of constants, [A B C]
% x: variables in array
% Example: rr=nest_fun(2:10,[1 2 4;2 4 8])
n = size(a);
  for i = 1:n
  A = a(i,1);B = a(i,2);C = a(i,3);
  rr_array{1,i}=['A=',num2str(A),', B=',...
      num2str(B),', C=',num2str(C)];
  rr_array{2,i}=polyx(x);
 end
  function r = polyx(xx)
    r = A.*x.^2 + B.*x +C;
  end
end

highlight.js works on some computer(s).
When I was writing the post, highlight.js didn't worked right, but as I gave up trying it and view this post on the next day, things just go fine.
Code copied from Applications of Matlab in Engineering. I'm not the only one to find out that the Matlab support of highlight.js is defective. [1]
We just see how google-code-prettify works.
function [rr_array] = nest_fun(x,a)
%function to find sets of polynormials.
% a: set of constants, [A B C]
% x: variables in array
% Example: rr=nest_fun(2:10,[1 2 4;2 4 8])
n = size(a);
  for i = 1:n
  A = a(i,1);B = a(i,2);C = a(i,3);
  rr_array{1,i}=['A=',num2str(A),', B=',...
      num2str(B),', C=',num2str(C)];
  rr_array{2,i}=polyx(x);
 end
  function r = polyx(xx)
    r = A.*x.^2 + B.*x +C;
  end
end
Note: In the official README, it's said that we specify the lang-* class by its file extension (i.e. m), but in the page that display the source code of lang-matlab.js on Google Code, it points to the author's Github repository, which has a README file. According to that file, the HTML tag should be <pre class="prettyprint lang-matlab">, instead of <pre class="prettyprint lang-m">.
So when one embeds the above source code list using google-code-prettify, one would write
<pre class="prettyprint lang-matlab">function [rr_array] = nest_fun(x,a)
%function to find sets of polynormials.
% a: set of constants, [A B C]
% x: variables in array
% Example: rr=nest_fun(2:10,[1 2 4;2 4 8])
n = size(a);
  for i = 1:n
  A = a(i,1);B = a(i,2);C = a(i,3);
  rr_array{1,i}=['A=',num2str(A),', B=',...
      num2str(B),', C=',num2str(C)];
  rr_array{2,i}=polyx(x);
 end
  function r = polyx(xx)
    r = A.*x.^2 + B.*x +C;
  end
end
</pre>
Let's go back to the topic.

SyntaxHighlighter

The SyntaxHighlighter code for embedding Java:
<pre class="brush: java">public class Hello {
    public static void main(String args[]) {
        System.out.println("Hello world!");
    }
}
</pre>
As the language in determined by brush: html, there's no multiple language feature in SyntaxHighlighter.

highlight.js

<pre class="brush: java">public class Hello {
    public static void main(String args[]) {
        System.out.println("Hello world!");
    }
}
</pre>
So highlight.js can display multiple languages at one container.

google-code-prettify

<pre class="brush: java">public class Hello {
    public static void main(String args[]) {
        System.out.println("Hello world!");
    }
}
</pre>
So the result of google-code-prettify is similar to that of SyntaxHighlighter.

Further results of highlight.js

We end this essay with more results in highlight.js.
In order to embed multilingual source code in a list, highlight.js is what you need, but if you insist on using google-code-prettify, here's some sample code.
<pre class="prettyprint">public class Hello {
    // Java code sample
        public static void main(String args[]) {
            System.out.println("Hello world!");
        }
    }

    <!-- CSS code-->
    .sidebar #sidebar, .ss{
     margin-top: 12px !important;
     overflow-y: scroll !important;
    }

    # C++ code
    #include <iostream>
    using namespace std;

    int main(void)
    {
        cout << "Hello world!" << endl;
        return 0;
    }
</pre>

Reference:
[1]: https://github.com/darcyclarke/Repo.js/issues/14

Testing Online Code Syntax Highlighters for Blogs (5): Embedding Makefiles to a Web Page

In my previous post titled Fast Compilation and Execution of Source Code, I included a makefile. After I've been familiar with SyntaxHighlighter, I changed the code of the makefile so that the new tool is used. However, as I've written in my earlier post, SyntaxHighlighter has no makefile support [1], while highlight.js and google-code-prettify have that feature. [2] [3]
I think, therefore I am.
Réné Descartes (1596–1650)
In order to be sure about their claims, I've done a test and the results are as follow.
highlight.js:
hello: hello.c
    gcc -o hello hello.c
clean:
    rm -f hello
Maybe my makefile is too simple that it lacks some typical features for the automatic language recognition of highlight.js. Let's see the sample code copied from the official demo.
# Makefile

BUILDDIR      = _build
EXTRAS       ?= $(BUILDDIR)/extras

.PHONY: main clean

main:
    @echo "Building main facility..."
    build_main $(BUILDDIR)

clean:
    rm -rf $(BUILDDIR)/*
google-code-prettify
hello: hello.c
    gcc -o hello hello.c
clean:
    rm -f hello
Let's see a real one.
# Makefile

BUILDDIR      = _build
EXTRAS       ?= $(BUILDDIR)/extras

.PHONY: main clean

main:
    @echo "Building main facility..."
    build_main $(BUILDDIR)

clean:
    rm -rf $(BUILDDIR)/*
Unluckily, I can't figure out the way to include a tab, instead of whitespaces, for makefiles. Anyways, one who use makefiles will know that after running make on the first day.
References:
[1]: http://alexgorbatchev.com/SyntaxHighlighter/manual/api/autoloader.html
[2]: http://highlightjs.org/static/test.html
[3]: http://google-code-prettify.googlecode.com/svn/trunk/README.html

Precautions to Changing Bloger's Template and Google Drive File Hosting

There are just two points to be noted for a change in the template of a blog.
  1. Backup the HTML template.
  2. Backup the CSS settings in "Template" → "Advanced" → "Add CSS"
Maybe what you need is just changing some properties of a CSS class. For instance, you've set the body background colour to be magenta and you want to change it to orange. This can be easily done if you put an external CSS style sheet to somewhere public on the web and include a link to the CSS style sheet in the HTML template of your blog. A very short documentation on Google Drive explains how the hosting of one's custom CSS stylesheet(s) on Google Drive can be done. Apart from shortening the time taken for changing the appearance of a blog, it avoids the loss of CSS code due to Blogger's problems and/or users' mistakes.