Sunday, September 23, 2012

vi: Removing Endline Character ^M

A text file commutes between Linux and Windows may cause the endline control character explicitly printed as ^M.
To remove all control characters, under command mode
Be aware that ^M is created by pressing ctrl + v (^) and then ctrl + M (M).
The command is utilizing the Find and Replace under vi:
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
Ranges are
% - the whole file
m,n - from line m to n
Pattern see vim reference.
Flags are
c - asks for confirmation at each replacement 
g - all the occurrences within a line
i - case insensitive
Count means to repeat for n times starting from the current line

Wednesday, September 19, 2012

php: Rendering text files in UTF-8

Pure .txt (even .utf8) files are rendered not as its natural encoding under Chrome (Version 21.0.1180.89 at present time). Then how to tell the browser to display it in the preferred encoding? We wrap it up via php and tell browser it requires utf-8.
  header('Content-Type: text/plain; charset=utf-8');

Monday, September 17, 2012

pdfpages: To Scale Freely

An improperly scaled pdf page requires tweaking its size. We use scale from graphicx to resize a page, combined with disabling auto-scale, offering an offset = {top, left}.
\usepackage{grffile}  %to treat the spaces in the file name if needed%
\usepackage{pdfpages,graphicx} %the package to do the combination job%
\includepdf[pages={1}, landscape, scale=1.1,noautoscale=true,offset={100 45}]
\includepdf[pages={2}, landscape, scale=1.4,noautoscale=true,offset={150 150}]

Saturday, September 1, 2012

Ubuntu: Enabling a webcam

The webcam is not detected. It indicates probably the driver is not installed, so we need to find the certain driver, and make it loaded by default. I am running Ubuntu 11.04 64bit on a Sony Vaio.

Use lsusb to find the device ID, as the case for me,
It is reported as a Ricoh R5U870 webcam, the driver is not preinstalled, among all the online drivers provided, the following one works, containing no compiling error and it has enabled the camera perfectly.

I quote the installation instructions here,
 $ sudo apt-get install libglib2.0-dev libusb-dev build-essential gcc 
  automake mercurial
 $ hg clone
 $ cd r5u87x
 $ make
 $ sudo make install
 $ sudo r5u87x-loader --reload
It recalls me of my experience on enabling the wireless function on a DELL Inspiron long ago. As ubuntu is designed to be universal, it still faces both legal and technical issues to include all possible drivers. This requires the holders of proprietary drivers to consent the public use such as in a Ubuntu release.