Blog 1

Random Talk on Random Thoughts

Installed Prawn

| Comments |

Problem

This noon, I tried to use the kramdown command line utility to generate PDF files, but failed.

$ kramdown test.tex -o pdf > test.pdf
/home/owner/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/ke
rnel_require.rb:55:in `require': cannot load such file -- prawn (LoadError)
	from /home/owner/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygem
s/core_ext/kernel_require.rb:55:in `require'
	from /home/owner/.rvm/gems/ruby-2.1.2/gems/kramdown-1.4.1/lib/kramdown/c
onverter/pdf.rb:10:in `<top (required)>'
	from /home/owner/.rvm/gems/ruby-2.1.2/gems/kramdown-1.4.1/lib/kramdown/d
ocument.rb:119:in `const_defined?'
	from /home/owner/.rvm/gems/ruby-2.1.2/gems/kramdown-1.4.1/lib/kramdown/d
ocument.rb:119:in `method_missing'
	from /home/owner/.rvm/gems/ruby-2.1.2/gems/kramdown-1.4.1/bin/kramdown:6
1:in `block in <top (required)>'
	from /home/owner/.rvm/gems/ruby-2.1.2/gems/kramdown-1.4.1/bin/kramdown:6
1:in `each'
	from /home/owner/.rvm/gems/ruby-2.1.2/gems/kramdown-1.4.1/bin/kramdown:6
1:in `<top (required)>'
	from /home/owner/.rvm/gems/ruby-2.1.2/bin/kramdown:23:in `load'
	from /home/owner/.rvm/gems/ruby-2.1.2/bin/kramdown:23:in `<main>'
	from /home/owner/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `e
val'
	from /home/owner/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<
main>'

Understood Power Means Inequality for Integer Powers

| Comments |

I’ve learnt the AM–GM–HM inequality when I was a secondary school student.

\[ \frac1n \sum\limits_{i=1}^n x_i \ge \sqrt[n]{\prod_{i=1}^n x_i} \ge \frac{n}{\sum\limits_{i=1}^n x_i^{-1}} \]

But I didn’t know how to generalise it to integer power $s$. That is, if $k$ and $m$ are positive integers such that $k \le m$, then we have

\[ \left( \frac1n \sum\limits_{i=1}^n x_i^k \right)^{1/k} \le \left( \frac1n \sum\limits_{i=1}^n x_i^m \right)^{1/m}. \]

I read the proof in Wikipedia, and got stuck in the first step.

\[ \frac{\sum\limits_{i=1}^{n} w_{i}x_{i}^{k}}{\sum\limits_{i=1}^{n} w_{i}x_{i}^ {k-1}} \le \frac{\sum\limits_{i=1}^{n} w_{i}x_{i}^{k+1}}{\sum\limits_{i=1}^{n} w_{i}x_{i}^{k}} \]

I quickly realised that $w_i = 1/n$ in this case. Even though I know that the above inequality is eqivalent to

\[ \left( \sum\limits_{i=1}^n w_{i}x_{i}^{k} \right)^2 \le \left( \sum\limits_{i=1}^n w_{i}x_{i}^{k-1} \right) \left( \sum\limits_{i=1}^n w_{i}x_{i}^{k+1} \right). \]

At the first glance, I didn’t know how to relate this to the famous Cauchy–Schwartz inequality.

\[ \left( \sum\limits_{i=1}^n a_{i}b_{i} \right)^2 \le \left(\sum\limits_{i=1}^n a_{i}^2\right) \left(\sum\limits_{i=1}^n b_{i}^2\right) \]

Actually, setting $a_i = \sqrt{w_{i}x_{i}^{k-1}}$ and $b_i = \sqrt{w_{i}x_{i}^{k+1}}$ will do.

Rake Preview on M$ Win*

| Comments |

When I’d written an Octopress post and previewed the result, auto-regeneration of the contents weren’t available. In *nix, this should be enabled by running rake preview. Therefore, I followed the instructions of the command prompt, and the useful function was then enabled.

cmd prompt

Git Repositories in USB Drives on Windows

| Comments |

Problem

git bash

How to access my USB drive (F:/) in Git Bash?

I had tried closing all instances of Git Bash and re-opening them again.1 However, it didn’t worked.

Raison d’être

If users can use Git command line utilities in cmd.exe, then what’s the point of asking the above question?

Without stopping ssh-agent.exe, one can’t pull Git repositories from the hard disk to the USB drive.

Fixing Shellshock on Fedora 17

| Comments |

Background

A serious bug has been found affecting Linux and Mac OS X software, which security researchers claim could be bigger than Heartbleed.
...
Dubbed Shellshock, or the Bash Bug, the security vulnerability is officially known as CVE-2014-6271 and affects the Bash command processor which is used in most Linux distributions, in Apple's Mac OS X, and the Apache web server software, among others.
...
Which systems are affected?

Servers, home computers, and embedded devices are all vulnerable.

Users running Linux and Mac OS X on their PCs are at risk, but it is thought that the most likely target will be web servers running the Apache web server software.

And this is a big problem, especially when you consider that up to 60% of the web servers out there use this software.

Apache uses Bash to run background applications which process data from users, such as information inputted to online forms. If an attacker was able to exploit this vulnerability by making a web request which included exploit code, they would theoretically be able to launch widespread attacks on visitors to that website.

Ian Pratt, co-founder at Bromium told IBTimes UK: "It's going to impact large numbers of internet-facing linux/unix/OS X systems as bash has been around for many years and is frequently used as the 'glue' to connect software components used in building applications. Vulnerable network-facing applications can easily be remotely exploited to allow an attacker to gain access to the system."

In response to this bug, I’ve just checked if the bash on my Ubuntu desktop is safe.1 Actually, the necessary updates have been installed in the system.

Problem

I’ve also installed Fedora 17 two years ago.2 Nowadays, it’s no longer maintained by the package managers, who look after packages for newer versions of the GNU/Linux distribution.3

How can one fix the bash on Fedora 17?

I searched “shellshock fedora” on Google, and have learnt more about the security hole in Fedora Megazine.4

Shellshock: Better 'Bash' Patches Now Available

| Comments |

Luckily, the Ubuntu updater has already fetched the lastest patch of the vunerable bash.

$ env 'x=() { :;}; echo vulnerable' 'BASH_FUNC_x()=()
 { :;}; echo vulnerable' bash -c "echo test"
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `BASH_FUNC_x'
test

$ cd /tmp; rm -f /tmp/echo; env 'x=() { (a)=>\' bash 
-c "echo date"; cat /tmp/echo
date
cat: /tmp/echo: No such file or directory
$ 

What Are Good File Naming Conventions?

| Comments |

Computer users often use the whitespace character for file names. Actually, this will create problems in the Command Prompt or the Terminal.

Moreover, I’ve seen file names with Chinese characters. Since those characters aren’t alphnumeric, there will be a great trouble in viewing them in a file browser. How can one distinguish the different folders named in Chinese in the following figure?

tty1

A GUI user can argue that this is not a problem since he/she has ways to tell the difference between those folders with a Chinese name.

gui

However, it’s possible that the computer doesn’t have a good Chinese support, so one can’t view Chinese characters properly in GUI. Similarly, in order to avoid troubles, characters like ‘é’ and ‘ï’ shouldn’t be used in a file name.