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-11
Migration to WordPress
I tried finding a way to blog using Vim, and
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.
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.
I tried searching for
The
It took me some time to find out that I overlooked the command below
It still wouldn't compile with the OpenSSL feature. However, some features that had failed to compile before I had run the command
This inspired me to run the following commands.
Reference:
[1]: http://user.frdm.info/ckhung/a/c013.php
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] $ makeTherefore, 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-propertiesIn 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 reinstallBut 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 reinstallRemark: 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 reinstallHowever, 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 reinstallBut 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:
- Run the command
make clean
in both theruby-[version-number]
andruby-[version-number]/ext/openssl
directories. -
Run
make
inruby-[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 whatgdbm
is, I just proceed to the reinstallation of Ruby. -
Run the command
sudo make reinstall
inruby-[version-number]
.
Then the commandgem install bundle
in Oliver's guide should work.
- Always figure out the dependencies of a package.
- Be careful and patient while reading instructions on commands.
- 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
The HTML code for embedding the PDF document in 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.
Link for effective blogging:
Example of an error experienced by user on Blogger. |
- Susan Gunelius' Top 5 Reasons to Use an Offline Blog Editor
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
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.
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.
So when one embeds the above source code list using google-code-prettify, one would write
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.
Reference:
[1]: https://github.com/darcyclarke/Repo.js/issues/14
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). |
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 endNote: 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
highlight.js:
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
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.In order to be sure about their claims, I've done a test and the results are as follow.
Réné Descartes (1596–1650)
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 helloLet'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.
- Backup the HTML template.
- Backup the CSS settings in "Template" → "Advanced" → "Add CSS"
Testing Online Code Syntax Highlighters for Blogs (4): Giving up Using Blogger's Dynamic View
There are several reasons for the shift of the template of this blog from a dynamic view to a static one.
- Speed: Dynamic view takes too much time to load. This greatly slowed down my editing process on Blogger.
- Integration with other scripts: It is often quite troublesome to load other scripts using the dynamic view.
For example, due to my poor knowledge in HTML, JavaScript and CSS, I can't understand what's written on those blogs that use the dynamic view and manage to integrate with google-code-prettify and/or highlight.js work(s), such as Conrad's syntax highlight demo page and Wood's tutorial on using highlight.js. For details of my integration failure, you may see the last paragraph of my previous post.
As I'm not a web developer or a web designer, it's not worth spending so much time to goggle the solution. In contrast to the difficulty of installing external scripts in the dynamic view, the static view enables users to click "Layout" → "Add a Gadget" to do the job.
By doing so, the user doesn't need to edit HTML template every time. - More reasons can be found on 10 Reasons To Avoid Blogger Dynamic Views.
Testing Online Code Syntax Highlighters for Blogs (3): google-code-prettify
Here's another online code syntax highlighter called google-code-prettify.
The following are the test results.
In order to use this technology in your post, the following simple steps will do.
Reference:
[1]: http://andmobiz.blogspot.hk/2013/05/blogger-google-code-prettify-github-gist.html
The following are the test results.
In order to use this technology in your post, the following simple steps will do.
-
Add an "HTML/JavaScript" gadget to your blog. In the contents, just paste the following line of code found on the official tutorial. [1]
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
-
Insert the following lines of code and replace the text inside the
pre
tag with your code.
Note: Like SyntaxHighlighter and highlight.js, you need to encode<
,>
,&
, etc into HTML encoding using an HTML encoder. At the bottom part of one of my older posts, I included a link to an HTML encoder, and here's a list of two more.- Web 2.0 Generators: it contains a list of reserved characters and their entity names, as well as an HTML decoder.
- OpinionatedGeek: it contains an HTML decoder.
<pre class="prettyprint lang-html"> <!-- your code here--> </pre>
Then you use a HTML encoder to generate the following output and paste it inside thepre
tag<pre class="prettyprint lang-html"> <!-- your code here--> </pre>
Exercise: If you think that you understand the above text, try making a web page that teaches users how to embed HTML code into a web page.
Hint: Right click and choose "View Page Source" in the pop up menu. -
If your source code contains too many characters in a line, the right part of the code will go out of the box. Add the following CSS code to automatically fix the problem.
pre { overflow: auto; }
Then a scrollbar will be automatically attached to the source code container if the source code has too many columns and/or lines.
linenums
to the class
attribute of the pre
tag.
<select> <?php for ($i = 1; $i <= 2; ++$i) { ?> <optgroup label="<?php echo date('l j F', strtotime('+ ' . $i . ' day')); ?>"> <?php if($i==0) { ?> <?php for ($n = date('H'); $n < 16; $n += 3) { ?> <option><?php echo str_pad($n, 2, '0', STR_PAD_LEFT); ?>:00 - <?php echo str_pad($n + 2, 2, '0'); ?>:00</option> <?php } }?> <?php for ($n = 9; $n < 16; $n = $n + 3) { ?> <option><?php echo str_pad($n, 2, '0', STR_PAD_LEFT); ?>:00 - <?php echo str_pad($n + 2, 2, '0'); ?>:00</option> <?php } ?> </optgroup> <?php } ?> </select>For further details, refer to the official README.
Reference:
[1]: http://andmobiz.blogspot.hk/2013/05/blogger-google-code-prettify-github-gist.html
2014-01-07
Testing Online Code Syntax Highlighters for Blogs (2): highlight.js
Now I know the reason for failing to make highlight.js work on my blog yesterday. It is because of Blogger's dynamic view, which is the real thing that I'm going to give up using forever. For details, refer to my newer post.
(updated on 8/1/14 09:45 GMT)
(updated on 8/1/14 09:45 GMT)
Thanks to Chris, I know more ways of embedding source code lists now.
Confucius said that we need to practice what we've learnt. So this is my sample usage of highlight.js.
In my previous post titled Fast Compilation and Execution of Source Code, I included the following sample
makefile
:
hello : hello.c gcc -o hello hello.c clean: rm -f helloNote: See the note of making a makefile in the previous blog post. In order to include this list, I used Alex Gorbatchev's SyntaxHighlighter to do this.
<pre class="brush: text;">hello : hello.c gcc -o hello hello.c clean: rm -f hello </pre>This template looks pretty, but there's some inadequacies for me:
- Makefile (and other popular languages as well) support
- Multiple language syntax detection: For example, in the second source code list, I try to explain how to write the HTML code for including a source code list of another language (In this case, it's makefile).
@requires_authorization
def somefunc(param1='', param2=0):
r'''A docstring'''
if param1 > param2: # interesting
print 'Gre\'ater'
return (param2 - param1 + 1) or None
class SomeClass:
pass
>>> message = '''interpreter
... prompt'''
Code copied from the live demo of highlight.js.
A More User-Friendly and Dynamic View in Blogger
As you can see now, I no longer use the dynamic view in Blogger. For a more detailed reason, refer to my newer post.
(updated on 8/1/14 10:22 GMT)
Last Saturday, I changed the template from a dark one to a dynamic one withe sidebar. However, when I'd like to scroll down to my earlier essays, I found out that I need to go through some passages in between my current position and my target in the scrollbar. This is quite troublesome since a considerable amount of time is needed to load the contents of a blog entry.
Luckily, I could find out how Yoga changed his code in "Add CSS" in his template so as to get the sidebar on the left scrollable. I just copy the code from him for your reference.
.sidebar #sidebar, .ss{ margin-top: 12px !important; overflow-y: scroll !important; }Note: Later, I found out that without the scrollbar, the sidebar is still scrollable.
References:
[1]: http://www.southernspeakers.net/2012/09/scrollbar-for-sidebar-posts-in-blogger.html
2014-01-06
Testing Online Code Syntax Highlighters for Blogs (1): SyntaxHighlighter
This is a test of a guide for embedding code on Blogger found on Geed Talkin Siebel. I've some code that I'd like to share.
When I first learnt Java, I saw these few lines of code.
A year ago, when I looked at the official web page of Apache Commons FileUpload impatiently, I could get nothing from the sample code there. Fortunately, with the debugger in Eclipse, I managed to apply the knowledge on the user guide on that site. I'm sure that without any debugging tools, I can never get the job done!
Recently, when I backed up my files, I browsed a tutorial about extracting a zipped file on CodeJava and looked at the code there, and I've found out that even though I managed to use the
In the past few months, without any knowledge and effort to get a good display of the source code, I just typed the following codes directly into the HTML view of the WYSIWYG editor of Blogger.
After motivation, what's needed is action.
Following the guide mentioned above, I clicked the "copy to clipboard" icon at the top right-hand corner of relevant blocks of source code, and pasted them into the HTML of the template.
Without a successful experience of getting it work, I thought that the above guide didn't work and had treated it as another guide that I can't make use of. (After getting things work, I think I was unfair to its author by simply saying that "it doesn't work!")
I suspected that Blogger's dynamic view templates inhibits the use of SyntaxHighlighter, just like the case in MathJax, and would like to change the template of this blog. However, the space of displaying figures would be reduced. After that, I gave up this idea and tried to find some way to get SyntaxHighlighter work with the dynamic view. Then I found a detailed but a little bit complicated guide for impatient users on Crux Framework. Luckily, I managed to find another post on doing the same thing. It really saves the day! Pasting the three lines of code at the bottom, it finally works! Yes, there's just three lines, and here it is.
I can now start embedding source code into my blog posts. For an angled block
One final note: for indentation of source code with tabs, it's better to convert it to whitespaces first because toggling between the "Compose" and "HTML" modes of the online editor on Blogger will lead to disappearance of the tabs. The replacement is not difficult in Vim. Issuing the command
When I first learnt Java, I saw these few lines of code.
public class Hello { public static void main(String args[]) { System.out.println("Hello world!"); } }When I was still in secondary school, one of my classmates complained about the syntactic and conceptual complexity of the
print
method in Java. He said that it was a lot simpler in C++.
#include <iostream> using namespace std; int main(void) { cout << "Hello world!" << endl; return 0; }Deeply impressed by what I've done using Java, I didn't took his words. After several years, I looked at the code for handling zipped files in Apache Tomcat 2.5, and I understand him a little bit.
A year ago, when I looked at the official web page of Apache Commons FileUpload impatiently, I could get nothing from the sample code there. Fortunately, with the debugger in Eclipse, I managed to apply the knowledge on the user guide on that site. I'm sure that without any debugging tools, I can never get the job done!
Recently, when I backed up my files, I browsed a tutorial about extracting a zipped file on CodeJava and looked at the code there, and I've found out that even though I managed to use the
ZipInputStream
class to handle zipped archives, I still have no idea on how the machine works because the language is too high level.
The story ends here.In the past few months, without any knowledge and effort to get a good display of the source code, I just typed the following codes directly into the HTML view of the WYSIWYG editor of Blogger.
<pre> #include <iostream> using namespace std; int main(void) { cout << "Hello world!" << endl; return 0; } </pre>By doing so, the oupput is like this:
#include <iostream> using namespace std; int main(void) cout << "Hello world!" << endl; return 0; }Apart from unattractive appearance, the above list doesn't have line numbers. Though one can easily select and copy and code into a text editor, this is inefficient, when compared to SyntaxHighlighter.
After motivation, what's needed is action.
Following the guide mentioned above, I clicked the "copy to clipboard" icon at the top right-hand corner of relevant blocks of source code, and pasted them into the HTML of the template.
Don't worry about the single quotes in line 219. It works fine. |
Without a successful experience of getting it work, I thought that the above guide didn't work and had treated it as another guide that I can't make use of. (After getting things work, I think I was unfair to its author by simply saying that "it doesn't work!")
I suspected that Blogger's dynamic view templates inhibits the use of SyntaxHighlighter, just like the case in MathJax, and would like to change the template of this blog. However, the space of displaying figures would be reduced. After that, I gave up this idea and tried to find some way to get SyntaxHighlighter work with the dynamic view. Then I found a detailed but a little bit complicated guide for impatient users on Crux Framework. Luckily, I managed to find another post on doing the same thing. It really saves the day! Pasting the three lines of code at the bottom, it finally works! Yes, there's just three lines, and here it is.
<script type="text/javascript"> SyntaxHighlighter.highlight(); </script>After getting things done, I've realised that for dynamic views, there's only one missing step in the first guide, which is the last part of the last guide.
I can now start embedding source code into my blog posts. For an angled block
<tag>
, they need to be converted to <tag>
so that the JavaScript will run without errors. It is better to leave it to an online HTML encoder to do this tedious task.One final note: for indentation of source code with tabs, it's better to convert it to whitespaces first because toggling between the "Compose" and "HTML" modes of the online editor on Blogger will lead to disappearance of the tabs. The replacement is not difficult in Vim. Issuing the command
:[range]s:^\t: [num_of_times]:
will do. (It depends on the tabstop option on Vim. Adapt it according to your needs.)
2014-01-05
GNU ddrescue—A Powerful Data Recovery Tool
3 days ago, I encountered an error while moving a folder of about 3 GB
from my USB stick to my hard disk using GUI. After 1.2 GB of the files
are moved, the progress bar of the program just remained unchanged. I
left the seat in front of my computer and did something else. Returning
to the seat after half an hour, the situation had NOT been better. The
displayed remaining time was still "unknown".
The I clicked the cancel button to stop the process, but it simply hangs. After terminating the process from the "System Monitor" (another GUI program), the read/write speed of the USB stick became extremely low. Instead of blinking frequently, the light bulb inside the USB stick went on and off slowing during a read/write operation.
In
It's important to note that the data recovery program should never be run on the damaged device. Otherwise, further damage will be done to the damaged device. [1] In addition, I don't recommend running the data rescue tool on the operating system(s) installed on your hard disk. The process takes a long time, so "patience is key". [1]
Booted into the command line interface (CLI) of Ubuntu Rescue Remix 12.04, I first formatted the
After that , I ran the following command: [1]
In the screenshot below,
But the program refused to work, so I have to
The program read the blocks fast initially but it gradually slowed down. After running the command for over 20 hours, over 3700 MB of the data had been read. Although there's just about 400 MB to go, according to the average speed at that moment, it was an hour to recover 10 MB of the data. What's worse, the average speed was getting slower and slower! (Later, from GeekyProjects, I realised that the heat of the devices inhibits the process [2], and the logfile file feature enables users to pause the job. [3]) Therefore, always use a logfile. [4]
Without adequate knowledge on GNU ddrescue, I stopped the task with
Since then, I've really learnt a lesson: NOT to use GUI for copying big files, always use commands. Secondly, never use
Reference:
[1]: http://techmuck.blogspot.hk/2012/03/data-recovery-with-gnu-ddrescue.html
[2]: http://geekyprojects.com/storage/how-to-recover-data-even-when-hard-drive-is-damaged/
[3]: https://www.gnu.org/software/ddrescue/ddrescue.html
[4]: http://manpages.ubuntu.com/manpages/raring/man1/ddrescue.1.html
The I clicked the cancel button to stop the process, but it simply hangs. After terminating the process from the "System Monitor" (another GUI program), the read/write speed of the USB stick became extremely low. Instead of blinking frequently, the light bulb inside the USB stick went on and off slowing during a read/write operation.
In
/var/log/syslog.1
, it says[ 627.152020] usb 2-1: reset high-speed USB device number 4 using ehci_hcd [ 658.128020] usb 2-1: reset high-speed USB device number 4 using ehci_hcd [ 658.493165] sd 3:0:0:0: [sdf] Unhandled error code [ 658.493169] sd 3:0:0:0: [sdf] Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK [ 658.493174] sd 3:0:0:0: [sdf] CDB: Write(10): 2a 00 00 54 e9 30 00 00 01 00 [ 658.493188] end_request: I/O error, dev sdf, sector 5564720 [ 658.494531] quiet_error: 39 callbacks suppressed [ 658.494533] Buffer I/O error on device sdf1, logical block 5564658 [ 658.495808] lost page write due to I/O error on sdf1Oh! I need to recover the data! And I've found GNU ddrescue an excellent tool for the task. No expensive recovery plans are needed. Just ddrescue on a bootable media and some free space in a storage device will do.
It's important to note that the data recovery program should never be run on the damaged device. Otherwise, further damage will be done to the damaged device. [1] In addition, I don't recommend running the data rescue tool on the operating system(s) installed on your hard disk. The process takes a long time, so "patience is key". [1]
Booted into the command line interface (CLI) of Ubuntu Rescue Remix 12.04, I first formatted the
D
drive into an empty NTFS partition after backing up the data on that device. (i.e. /dev/sda5
)After that , I ran the following command: [1]
$ ddrescue -r1 -n -S -v /dev/sdxm /dev/sdyn [logfile] # Substitute x with the appropriate partition letter of the source partition # Substitute y with the appropriate partition letter of the destination partition # Substitute m with the appropriate partition number of the source partition # Substitute n with the appropriate partition number of the destination partitionThe process is irreverisible so do it carefully.
In the screenshot below,
x=f
, y=a
, m=1
, n=5
, and logfile=`backup1.log'
.But the program refused to work, so I have to
--force
it to work.Captured using screendump . |
The program read the blocks fast initially but it gradually slowed down. After running the command for over 20 hours, over 3700 MB of the data had been read. Although there's just about 400 MB to go, according to the average speed at that moment, it was an hour to recover 10 MB of the data. What's worse, the average speed was getting slower and slower! (Later, from GeekyProjects, I realised that the heat of the devices inhibits the process [2], and the logfile file feature enables users to pause the job. [3]) Therefore, always use a logfile. [4]
Without adequate knowledge on GNU ddrescue, I stopped the task with
<C-c>
, but it took the computer several minutes to receive this input. But what's next for an incomplete task? The files don't
occupy the whole USB stick. It might took me another day if I waited
for some while and then resumed the task. At that moment, I decided to
try mounting the destination partition /dev/sdyn
. Thinking that the destination was a NTFS partition from the partition table rendered by fdisk -l
, I tried mount -t ntfs /dev/sdyn
,
but the computer wouldn't let me go. I was fortunate to be stopped by
this error. Otherwise, I think I would do another harm to the file
system. This time, I let mount
to automatically decide the partition type by removing the -t
flag. It worked! I could browse and open the file there. After that, I copied the files to a safe place (i.e. a normal data storage device) Finally, I've found that most of the files were salvaged, despite some corruption of the multi-media files.Since then, I've really learnt a lesson: NOT to use GUI for copying big files, always use commands. Secondly, never use
mv
for big files, use cp
instead.Reference:
[1]: http://techmuck.blogspot.hk/2012/03/data-recovery-with-gnu-ddrescue.html
[2]: http://geekyprojects.com/storage/how-to-recover-data-even-when-hard-drive-is-damaged/
[3]: https://www.gnu.org/software/ddrescue/ddrescue.html
[4]: http://manpages.ubuntu.com/manpages/raring/man1/ddrescue.1.html
CUHK's Poor Guide for Password Generation
I
usually suggest users who refuse to use long passwords (>10
characters) for their online accounts to look at news on GPU password
cracking. [1] Setting a sufficiently long password is just the first
step. The variety of characters to be chosen is also crucial to
increasing the time taken for a brute force attack on the password. This
idea is supported by the CUHK's Guidelines for Setting a Strong Password, which is the main concern in the post.
The problem is NOT large if the user has some common sense on how the Internet works. However, as a guide for common end users of online services, the last section "Useful tools" is a little bit misleading. If you know some engineering students, he/she will tell you that making things work is their main goal. They can come up with fancy ways to hide standard errors from users. According to our naked eyes, the so called "random password generator" seems to be able to generate random passwords. However, you don't actually know the algorithm used. [2] Are they random enough? Are there any ways of predicting the output of the online password generators? The Community Ubuntu Documentation provides us a three-pronged reason for NOT actually using the "secure password generators" listed in the last section of CUHK's guide.
By saying that those tools "may assist you to set a strong password", the guide is far from wrong, but also far from good. For a proper introduction to a decent password policy for common users, go to [2] of the reference list for Ubuntu's guide.
P.S. The CUHK's guide have been writen for a long time. As I've mentioned above, a GPU cracks passwords much faster than before, so the figures need to be either updated or simply replaced with a link to a web page introducing recent technology on brute force password attacks.
References:
[1]: http://www.linuxjournal.com/content/hack-and-password-cracking-gpus-part-i-setup
[2]: https://help.ubuntu.com/community/StrongPasswords
The problem is NOT large if the user has some common sense on how the Internet works. However, as a guide for common end users of online services, the last section "Useful tools" is a little bit misleading. If you know some engineering students, he/she will tell you that making things work is their main goal. They can come up with fancy ways to hide standard errors from users. According to our naked eyes, the so called "random password generator" seems to be able to generate random passwords. However, you don't actually know the algorithm used. [2] Are they random enough? Are there any ways of predicting the output of the online password generators? The Community Ubuntu Documentation provides us a three-pronged reason for NOT actually using the "secure password generators" listed in the last section of CUHK's guide.
By saying that those tools "may assist you to set a strong password", the guide is far from wrong, but also far from good. For a proper introduction to a decent password policy for common users, go to [2] of the reference list for Ubuntu's guide.
P.S. The CUHK's guide have been writen for a long time. As I've mentioned above, a GPU cracks passwords much faster than before, so the figures need to be either updated or simply replaced with a link to a web page introducing recent technology on brute force password attacks.
References:
[1]: http://www.linuxjournal.com/content/hack-and-password-cracking-gpus-part-i-setup
[2]: https://help.ubuntu.com/community/StrongPasswords
2014-01-04
Giving up Testing MathJax and Anchors on Blogger
In
dynamic view, though the code for dynamic loading of MathJax contents
has been pasted into the HTML code for the template, things just work in
a strange way: in the class mode, MathJax works the best; in other
modes, it
may not work or it works partially. For example, in a mode, the dollar
sign in the code tag is interpreted, and the script file for MathJax is
loaded. But when you click a blog entry for a popup frame containing
some MathJax code, then it simply won't load. Nonetheless, anchors don't
work in a desired way in the dynamic view—after clicking an anchor, I
am immediately directed to the destination, which is covered by the
header. Finally, to ensure that the contents are correctly interpreted,
the best way is to use the
References:
[1]: http://github.com/mathjax/mathjax-docs/wiki/How-to-prevent-rendering:-use-tex2jax_ignore
tex2jax_ignore
class. [1]
Anyways, if readers are also writers of HTML, $\rm \LaTeX$, etc, they'll
know what I intend to write by testing the HTML code, and for the
remaining readers, I just apologize for the inconvenience caused and
suggest them to right click the article in the default "Sidebar" view
and press <F5>
to reload for the correctly rendered contents. I've forgotten about anchors since toggling between the "Compose" and "HTML" modes while writing a new post will cause some strange change in the href
attribute of the a
tag.References:
[1]: http://github.com/mathjax/mathjax-docs/wiki/How-to-prevent-rendering:-use-tex2jax_ignore
Escaping '$' in MathJax
Anyone who are used to $\rm \LaTeX$'s
After pasting the code inside the
Imagine that you want to compare the price of a product of different companies. You then typed two prices on the same line.
In order to get the problem fixed, I searched "mathjax escape dollar sign" and found Stack Overflow question 8773586 very useful. Following the first answer for the question, I managed to get it right. That is, to change the it like this:
$
character$
for switching to inline math mode would like to use the same command for the same thing on MathJax, which suggests the use of backslashed parentheses to enclose an inline math equation. As a result, in the very first part of MathJax's official documentation, it contains several lines code for that.After pasting the code inside the
head
tag, the above problem is solved, but this method creates another problem.Imagine that you want to compare the price of a product of different companies. You then typed two prices on the same line.
<p>...</p> <p>Nowadays, it costs nearly $500. In the past, it only costs around $300. It's too expensive!</p> <p>...</p>Then the web browser will interpret the contents in this way:
Wrongly interpreted contents |
<p>...</p> <p>Nowadays, it costs nearly <span class="tex2jax_ignore">$</span>500. In the past, it only costs around <span class="tex2jax_ignore">$</span>300. It's too expensive!</p> <p>...</p>
Correctly interpreted contents |
Subscribe to:
Posts (Atom)