Wednesday, November 27, 2013

Convert from pdf to djvu on Linux

One of the main reasons to convert a pdf file into djvu file is to save space.


on Linux:

sudo apt-get install pdf2djvu
pdf2djvu -o output_file input_file

If you want to convert djvu to pdf, then you have to install a package from here.
Read more ...

Thursday, September 26, 2013

Latex 对齐方式

LaTeX 对齐方式

一行对齐:
\leftline{左对齐} \centerline{居中} \rightline{右对齐}

多行或者段落对齐:
左对齐 \begin{flushleft}...\end{flushleft},
居中 \begin{center}...\end{center}
右对齐 \begin{flushright}...\end{flushright}


LaTeX公式左对齐
LaTeX中公式默认是居中对齐的, 但有时我们希望它能左对齐, 使用的方法如下:

1. \documentclass[a4paper,fleqn]{article} 这个对整篇文章有效.

如果只需要对一行公式进行左对齐的话, 可使用
\begin{flalign}
your equation (1)
\end{flalign}


2. 对某一个公式:
some text here\\
your equation here
and more text here.


3. 如果你说的是某一个公式有两三行, 你想把这几行做左对齐.
\begin{flalign}
\begin{split}
your equation (1)
your equation (2)
\end{split}&
\end{flalign}


还有其它方法,
例如使用 左对齐、居中对齐、右对齐的环境分别为flushleft、center和flushright。也可以使用命令\raggedright、\centering和\raggedleft使以后的文本按指定方式对齐.

或者

加载amsmath宏包后,使用选项fleqn(就是声明加载宏包时使用\usepackage[fleqn]{amsmath})可以使本该居中对齐的行间公式改为左对齐.
Read more ...

Solution to iPad “Not Charging” When Connected to Computer USB

Download the software > ASUS Ai Charger
Read more ...

Sunday, September 15, 2013

Java 1.6.0_51 breaks MATLAB 2012b

The was an issue in the Java security updates that Apple released for Mac OS X (as mentioned above). These updates install Java 1.6.0_51 and the exact build number looks like this (ending with M4508):
Java™ SE Runtime Environment (build 1.6.0_51-b11-456-10M4508) You can check if you have installed the xM4508 versions by running any one of the following commands on the Terminal of your Mac OS X:
java -version 
OR
/usr/libexec/java_home -v 1.6 -exec java -version 
If you have previously installed the xM4508 versions of the Java updates you can upgrade to the fixed xM4509 version by manually installing the following update:
Mac OS 10.7.x and 10.8.x:
================
Mac OS 10.6.x:
================
Confirm that you have the updated Java version by executing any of the above two commands. The exact build number looks like this (ending with M4509):
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-10M4509)
updates already (ending with M4508), you should receive this fix (ending with M4509) automatically through Software Update / App Store.

source: here
Read more ...

Wednesday, August 14, 2013

Monday, July 15, 2013

Cut or trim mp3 files with Linux

Link.


We are going to see two different options:

1. mpgtx
To install this program under Debian
$ sudo aptitude install mpgtx
Now if you want to trim a mp3 file into 10 pieces just enter this command
mpgtx -10 input.mp3 -o output
You will get output01.mp3, output02.mp3 .... output10.mp3 files, and now you can easily transport them, use them as ringtones, or anything you need.
Now if you want to cut an specific part of the mp3 file you may use ranges:
$ mptsplit input.mp3 [00:00:20-00:00:58] -o output.mp3
Now you will have from the 20th second to the 58th second of the song, in output.mp3 file, which is great for creating ringtones for your cellular.
Read the man page for more options, as you can also join files and some other useful things.

2. mp3cut
First install the program, mp3cut is one tool, of the mp3 suite tools called poc-streamer, so lets install the suite of tools.
$ sudo aptitude install poc-streamer
Now to cut or trim the mp3 files, it works a lot like the first option in this article, lets try the same example.
$ mp3cut -o output.mp3 -t 00:00:20+000-00:00:58+000 input.mp3
This will have the same effect and you will get a resulting file containing the song from the 20th second to the 58th second.
Do not forget to check the man page, and also to hear to your resulting files also from the command line check out: mpg123
Read more ...

Tuesday, July 9, 2013

X Forwarding with Putty on Windows

Prerequisites

Configuring Putty
  1. Add Unix hostname/IP address
  2. Switch Protocol to SSH
  3. Type name of session in saved sessions
  4. Click 'Save'
  5. Expand the 'SSH' tab from the 'Category' list
  6. Choose 'X11' from 'SSH' list
  7. Check 'Enable X11 Forwarding'
  8. Put localhost:0 to X display location
  9. Choose 'Session' from 'Category' list
  10. Click 'Save'
Connecting
  1. Start Xming
  2. Start Putty
  3. Double click on the saved session you want
via: here

Read more ...

Windows 下配置 Latex

首先安装 MiKTeX 或者 TexLive
然后安装 TeXstudio

MiKTeX 的 texmf 路径可以通过 MiKTeX Options (Admin) 程序查看

打开 MiKTeX Options (Admin)
选择 Roots
勾选 Show MiKTeX-mantained root directories

就可以看到了

第三方的 theme 可以直接放到这里面

另外安装 package 可以用 Package Manager (Admin) 程序安装
如果是下载好的宏包安装
可以打开 Package Manager (Admin)
选择 Repository
选择 Change Package Repository
选择 Package shall be installed from a directory
Read more ...

Thursday, June 27, 2013

Debian change default display manager and session

To change default display manager
$  sudo nano /etc/X11/default-display-manager

To change default session
$ update-alternatives --config x-session-manager
Read more ...

Wednesday, June 26, 2013

Linux command for username and group

Change or rename user name and UID (user-id)
# usermod -l <new_username> <old_username>
# usermod -u UID <username>

List username from a group
# getent group <groupname>

Remove username from a group
# gpasswd -d <username> <group>

Remove/Delete a user account
# userdel <username>
The following command will also remove user home directory
# userdel -r <username>

Add user to a group
# adduser <username> <group>
Read more ...

Control Volume with Keyboard Shortcut in Xfce

Add an Xfce shortcut by going to Applications > Settings > Keyboard.

Code for volume up/down/mute

amixer set Master 3%+
amixer set Master 3%-
amixer set Master toggle


Read more ...

Friday, June 21, 2013

Ubuntu/Debian 下安装 VirtualBox 虚拟 Win7

官方网站:http://www.virtualbox.org/

VirtualBox中虚拟Win7
运行Vbox
–》单击左上角New,新建虚拟环境。
–》填写名称和将要虚拟的操作系统版本。
–》然后是内存设置,默认即可,如果host主机内存够大,可以多设。
–》接下来虚拟硬盘,一路默认即可,最后确认,完成。

安装Win7
–》准备好系统镜像。win7.iso。
–》单击左上角Settings,会提示:Failed to access the USB subsystem.VirtualBox is not currently allowed to access USB devices. You can change this by adding your user to the ‘vboxusers’ group. Please see the user manual for a more detailed explanation.
将用户名添加到vboxusers组,重启或注销后即可解决。
sudo adduser usrname vboxusers
–》选择Storage,在看到IDE controler控制器下有硬盘和光盘, 光盘显示Empty,点击右侧Attributes属性中CD/DVD drive 右边的光盘图像,Set up the virtual CD/DVD drive,选择硬盘上下载的iso镜像文件,创建虚拟光驱。如果下面的步骤无法继续,在这里还可以尝试添加Sata 控制器。
–》设置好Storage点击Start 开始。接下来和普通安装Win7一样了。
–》安装完。优化设置,重新安装有问题的主板驱动;配置网络:如果无法上网,Settings中设置network从AMD换为intel(r) PR0/1000 MT Network Connection等,启动网卡驱动安装。

设置共享文件
Guest(win)
–》在Settings – Share Folders 点击+号新建共享文件夹,可选择Auto Mount 自动挂载。
–》点击顶部菜单设备device选项–Install Guest Additions,进行安装。
安装完毕,即可看到共享文件夹。

Guest(linux)

For linux guest, You may have to install following packages to complete Guest additions.

To dispaly the KERNELVERSION of the running distribution, you can use
uname -r

sudo apt-get install xserver-xorg xserver-xorg-core build-essential linux-headers-KERNELVERSION dkms
  1. sudo mkdir /media/shared  
  2. sudo mount.vboxsf Share /media/shared  
  3. sudo gedit /etc/fstab  
add the following into fstab:
Share /media/shared vboxsf rw 0 0
Share 为你要共享的文件夹 可以在settings里面设置。


支持USB
VirtualBox启用USB 2.0 必须安装:Oracle VM VirtualBox Extension Pack for Windows。在窗口顶部菜单File-Preferance-Extensions中添加下载的extpack。最后在Settings的usb选项中启用USB2.0,然后添加usb设备,即可。

摄像头驱动
同样在USB设置中添加摄像头。然后到虚拟的Win7里面安装相应驱动即可。
 
Read more ...

MATLAB FUNCTION accumarray

A = accumarray(subs,val,sz,fun,fillval)
  sub:提供累计信息的指示向量
   val:提供累计数值的向量
    sz:控制输出向量A的size
   fun:用于计算累计后向量的函数,默认为@sum,即累加
fillval:填补A中的空缺项,默认为0


例子:

  1. myfun = @(x) 1./(2*numel(x)) * sum(x);  

myfun = 

    @(x)1./(2*numel(x))*sum(x)

  1. subs=[7,2,5,7,2]';  

subs =

     7
     2
     5
     7
     2

  1. val=1:5;  

val =

     1     2     3     4     5

  1. sz=[10,1];  

sz =

    10     1

  1. A=accumarray(subs,val,sz,myfun,nan);  

A =

       NaN
    1.7500
       NaN
       NaN
    1.5000
       NaN
    1.2500
       NaN
       NaN
       NaN

个人对此函数的理解:
首先,函数根据参数中sz,生成一个中间矩阵B,此例中sz=[10,1],所以B是一个10*1的矩阵。
然后,函数根据subs中的指示,将val中的数值摆放到B中。
  subs  val
     7     1
     2     2
     5     3
     7     4
     2     5
意思就是,val中的1被扔到了B中第7的位置,同样,2扔到B中第2个位置,3到B中5,4到B中7,5到2。
这样B中的2,5,7位就被摆放上了数值,而且,2和7两个位置上被摆上了2个数值。

B =

   NaN
   2,5
   NaN
   NaN
   3
   NaN
   1,4
   NaN
   NaN
   NaN
其他还有7个位置并没有被摆放任何数值,我们暂时不管他,给他扔上NaN。
然后,accumarray函数就会根据自定义的函数myfun,来计算了。拿什么算呢,拿的就是这个中间矩阵B,我们定义的myfun意义就是均值的一般,所以也可以定义的时候写成:

  1. myfun = @(x) mean(x)./2;  

这下就简单了,就相当于mean(B)./2,然后得出的结果就是A了。
A =

       NaN
    1.7500
       NaN
       NaN
    1.5000
       NaN
    1.2500
       NaN
       NaN
       NaN
个人理解大概是个这样的过程,接下来再去看matlab的help文件就比较容易懂了。
Read more ...

MATLAB中的共轭转置与非共轭转置

对已知矩阵A,MATLAB为我们提供了两种转置运算。
A.' 非共轭转置

A' 共轭转置

单纯地共轭用:conj()
非共轭可以用:transpose()

example:
  a =
        12.0000                  0 + 2.0000i         5.0000         
        0                             5.0000               4.0000 
>> a'
             ans =
                      12.0000                  0         
                      0 - 2.0000i              5.0000         
                      5.0000                    4.0000         
>> a.'
           ans =

                   12.0000                  0         
                  0 + 2.0000i              5.0000         
                  5.0000                    4.0000

Read more ...

决定系数和残差

首先看看几个定义:
总体平方和TSS( total sum of squares)
回归平方和RSS(regression sum of squares)
残差平方和ESS(Residual sum of squares)
其中yi表示实验数据,fi 表示模拟值,表示样本平均值。
决定系数(Coefficient of determination)

在一定程度上反应了模型的拟合优度。
其实就是回归平方和在总体平方和中所占的比例。因为TSS=RSS+ESS
The better the linear regression (on the right) fits the data in comparison to the simple average (on the left graph), the closer the value of R2 is to one. The areas of the blue squares represent the squared residuals with respect to the linear regression. The areas of the red squares represent the squared residuals with respect to the average value.
红色区域是总体平方和,蓝色为残差平方和。
>> 为什么要用决定系数去反应拟合优度,而不用残差平方和呢?
>> 因为,残差平方和与观测值的绝对大小有关,而决定系数是一个比例。
比如:有一组数据:1000,2000,35000...
            另一组数据:1,2,3.5...
这个时候就会发现第一组数据的拟合后残差平方和会大很多,但是不见得,模型拟合优度就会差。
Read more ...

Latex(Emacs+Auctex+Jabref)中参考文献处理

>> 文献管理用 Jabref,可以很方便的管理文献,其 BibTeX 文献数据库可供 Latex 或其他软件使用,可与 emacs,vim,kile 等多种软件结合使用。所有文献信息都被记录在bib文件中。格式如下(myref.bib)。

  1. @ARTICLE{Journel1994,  
  2.   author = {Journel, André and Xu, Wenlong},  
  3.   title = {Posterior identification of histograms conditional to local data},  
  4.   journal = {Mathematical Geology},  
  5.   year = {1994},  
  6.   volume = {26},  
  7.   pages = {323-359},  
  8.   note = {10.1007/BF02089228},  
  9.   __markedentry = {[mao]},  
  10.   abstract = {Stochastic simulation techniques which do not depend on a back transform  
  11.     step to reproduce a prior marginal cumulative distribution function  
  12.     (cdf) may lead to deviations from that distribution which are deemed  
  13.     unacceptable. This paper presents an algorithm to post process simulated  
  14.     realizations or any spatial distribution to reproduce the target  
  15.     cdf in the case of continuous variables or target proportions in  
  16.     the case of categorical variables, yet honoring the conditioning  
  17.     data. Validations conducted for both continuous and categorical cases  
  18.     show that. by adjusting the value of a correction level parameter  
  19.     , the target cdf or proportions can be well reproduced without significant  
  20.     modification of the spatial correlation patterns of the original  
  21.     simulated realizations .},  
  22.   affiliation = {Stanford University Geological and Environmental Sciences Department  
  23.     94305 Stanford California},  
  24.   issn = {0882-8121},  
  25.   issue = {3},  
  26.   keyword = {Earth and Environmental Science},  
  27.   owner = {mao},  
  28.   publisher = {Springer Netherlands},  
  29.   timestamp = {2011.10.13},  
  30.   url = {http://dx.doi.org/10.1007/BF02089228}  
  31. }  

>> 用 Emacs+Auctex 写文章时参考文献的引用方法:
首先将 bib 文件放到 tex 同一目录下,在 tex 文档中加入

  1. \bibliographystyle{ieeetr}  
  2. \bibliography{myref}  

这里,bibliographystyle 有很多种,可以查看 /usr/share/texmf-texlive/bibtex/bst/base 里面的bst文件。接下来我们就可以用 \cite{} 来引用文献库中的论文了,在emcas中可以直接C-c [ 来插入,不过需要开启 reftex mode。 M-x reftex-mode <RET>开启,然后点开 Ref 选项 --> Parse Document --> Entire Document。当然也可以编辑.emacs文件,添加

  1. (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode  
  2. (setq reftex-external-file-finders   
  3. '(("tex" . "kpsewhich -format=.tex %f")   
  4. ("bib" . "kpsewhich -format=.bib %f")))  

>> An example

  1. \documentclass[11pt,a4paper]{article}  
  2. \usepackage{bm} % for math symbols bold  
  3. \usepackage{amsmath,amssymb,amsfonts}  
  4.   
  5. \title{A short Note on Everything\\[1ex] \begin{large} \LaTeX{} is  
  6. cool \end{large}}  
  7. \author{Ganquan Mao}  
  8. \date{}  
  9.   
  10. \bibliographystyle{ieeetr}  
  11. \begin{document}  
  12. \maketitle  
  13.   
  14. \input{seckrig}  
  15. %\include{}  
  16. an example.\cite{Journel1994}  
  17.   
  18. \bibliography{myref}  
  19.   
  20. \end{document}

p.s. In emacs, you can just type C-c [ then write a keyword, press enter to search for papers
Read more ...

Set another viewer for auctex in emacs

>> Open an tex file;
>> LaTeX -> Customize AUCTeX -> Extend this menu;
>> Then LaTeX -> Customize AUCTeX -> TeX Command -> TeX Output View Style;
>> Find a line somehow like ''Extension: ^pdf";
>> Change Command to viewer you want. e.g. evince %o %(outpage) to okular %o %(outpage);
>> Click “Save for future sessions”.
Read more ...

Linux 下批量解压文件

find -maxdepth 1 -name "*.bz2" | xargs -i tar xvjf {}  
这条命令可解压当前目录下的所有bz2文件。maxdepth表示搜索深度,1代表只搜索当前目录。

find -maxdepth 1 -name "*.tar" | xargs -i tar xvf {}  
可解压tar文件。

find -maxdepth 1 -name "*.tar.gz" | xargs -i tar zxvf {}  
可解压tar.gz文件。
Read more ...

Linux 下批量去后缀加后缀

1. 删除所有的 .xml 后缀

$ rename 's/\.xml$//' *.xml  

2. 给当前目录下所有文件加后缀 .xml

for i in *  
   do mv $i $i".xml"  
done  
Read more ...

利用 ssh -X 登录服务器打开 xterm 等

>> 首先确保 /etc/ssh/sshd_config 中

X11Forwarding yes

>> 然后在 host 上 check DISPLAY

$ echo $DISPLAY

如果显示 

:0
继续输入

$ export DISPLAY=urworkstationIP:0.0

urworkstationIP 就是你想要显示 xterm 的客户端的IP。

>> 然后登录是使用

$ ssh -X host
Read more ...

MATLAB 中用 spline 代替 solve/finvers 数字求解反函数

example:

  1. Cg=sym('exp(-((-log(u))^alpha + (-log(v))^alpha)^(1/alpha))');  
  2.   
  3. cu=diff(Cg,'u');  
  4. c=subs(cu,{'u','alpha'},[0.8,2]);  
  5.   
  6. vr=linspace(0,1,1000);  
  7. tr=subs(c,'v',vr);  
  8.   
  9. t=rand(100,1);  
  10. v=spline(tr,vr,t);  

如果直接用solve/finvers求解c。matlab提示无解。
##
cu是Cg对u的偏导,c为偏导函数中带入u=0.8 alpha=2得到的只含变量v的函数。
vr和tr是为了生成一定数量的pairs,以便spline函数求反函数的时候插值。

  1. plot(vr,tr,'--')  

可以看到c函数的图。
t为随机生成的100个点,v是这100个点对应的反函数值!
如果是:

  1. v=spline(vr,tr,t);  

那么就是简单的插值。
help spline
可以看到spline的相关功能和用法。
Read more ...

wget 使用技巧

wget 是一个命令行的下载工具。对于我们这些 Linux 用户来说,几乎每天都在使用它。下面为大家介绍几个有用的 wget 小技巧,可以让你更加高效而灵活的使用 wget。
  • $ wget -r -np -nd http://example.com/packages/
这条命令可以下载 http://example.com 网站上 packages 目录中的所有文件。其中,-np 的作用是不遍历父目录,-nd 表示不在本机重新创建目录结构。
  • $ wget -r -np -nd --accept=iso http://example.com/centos-5/i386/
与上一条命令相似,但多加了一个 --accept=iso 选项,这指示 wget 仅下载 i386 目录中所有扩展名为 iso 的文件。你也可以指定多个扩展名,只需用逗号分隔即可。
  • $ wget -i filename.txt
此命令常用于批量下载的情形,把所有需要下载文件的地址放到 filename.txt 中,然后 wget 就会自动为你下载所有文件了。
  • $ wget -c http://example.com/really-big-file.iso
这里所指定的 -c 选项的作用为断点续传。
  • $ wget -m -k (-H) http://www.example.com/
该命令可用来镜像一个网站,wget 将对链接进行转换。如果网站中的图像是放在另外的站点,那么可以使用 -H 选项。
Read more ...

利用 MATLAB 对文件批量重命名

>> matlab 中 strrep 函数可以更改文件扩展名。
>> matlab 中 unix system ! 都可以让你在 matlab 中执行系统命令。
比如:

  1. !mv a.tex b.tex  
  2. unix('mv a.tex b.tex')  
  3. system('mv a.tex b.tex')  

>> 再加上 dir 函数 以及一个 for-loop 就可以对文件进行批量重命名了。
当然,windows 下应该是用 rename 重命名。
Read more ...

Beamer 中指定 item 前面的符号


  1. \begin{itemize}  
  2.   \setbeamertemplate{itemize items}{\color{red}$\bullet$}  
  3. \item one  
  4. \item two  
  5. \item three  
  6. \end{itemize}  

$\bullet$ 可换成任何符号, 比如 \checkmark
或者

  1. \setbeamertemplate{items}[ball]  
Read more ...