Thursday, July 31, 2014

solve: "X11 forwarding request failed on channel 0" problem after disable ipv6 of centos

1. Started sshd in debug mode (sudo rc.d stop sshd, sudo /usr/sbin/sshd -d)
2. Noticed Failed to allocate internet-domain X11 display socket. in debugging output
3. The page http://forums.fedoraforum.org/showthread.php?t=270333 indicates a possible relation to IPv6 being disabled.
4. Checked sysctl net.ipv6.conf.all.disable_ipv6, and indeed, IPv6 was disabled.
5. Re-enabled by undoing https://wiki.archlinux.org/index.php/IPv6_-_Disabling_the_Module
5'. Alternatively, adding AddressFamily inet to /etc/ssh/sshd_config would have also worked


comments: the (5) is good if you have to disable ipv6.

Monday, July 28, 2014

install EPEL repor for Centos

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
 
reference:
https://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F 

Friday, June 13, 2014

multi functions in one matlab M file.

he first function in an m-file (i.e. the main function), is invoked when that m-file is called. It is not required that the main function have the same name as the m-file, but for clarity it should. When the function and file name differ, the file name must be used to call the main function.
All subsequent functions in the m-file, called local functions (or "subfunctions" in the older terminology), can only be called by the main function and other local functions in that m-file. Functions in other m-files can not call them.
In addition, you can also declare functions within other functions. These are called nested functions, and these can only be called from within the function they are nested. They can also have access to variables in functions in which they are nested, which makes them quite useful albeit slightly tricky to work with.
More food for thought...
There are ways around the normal function scoping behavior outlined above, such as passing function handles as output arguments as mentioned in Jonas' answer. However, I wouldn't suggest making it a habit of resorting to such tricks, as there are likely much better options for organizing your files.
For example, let's say you have a main function A in an m-file A.m, along with local functions D, E, and F. Now let's say you have two other related functions B and C in m-files B.m and C.m, respectively, that you also want to be able to call D, E, and F. Here are some options you have:
  • Put D, E, and F each in their own separate m-files, allowing any other function to call them. The downside is that the scope of these functions is large and isn't restricted to just A, B, and C, but the upside is that this is quite simple.
  • Create a defineMyFunctions m-file (like in Jonas' example) with D, E, and F as local functions and a main function that simply returns function handles to them. This allows you to keep D, E, and F in the same file, but it doesn't do anything regarding the scope of these functions since any function that can call defineMyFunctions can invoke them. You also then have to worry about passing the function handles around as arguments to make sure you have them where you need them.
  • Copy D, E and F into B.m and C.m as local functions. This limits the scope of their usage to just A, B, and C, but makes updating and maintenance of your code a nightmare because you have three copies of the same code in different places.
  • Use private functions! If you have A, B, and C in the same directory, you can create a subdirectory called private and place D, E, and F in there, each as a separate m-file. This limits their scope so they can only be called by functions in the directory immediately above (i.e. A, B, and C) and keeps them together in the same place (but still different m-files):
    myDirectory/
        A.m
        B.m
        C.m
        private/
            D.m
            E.m
            F.m
All this goes somewhat outside the scope of your question, and is probably more detail than you need, but I thought it might be good to touch upon the more general concern of organizing all of your m-files. ;)

Tuesday, April 15, 2014

linux, find a line in a file and delete it, by using "sed"

 Q: need to grep for a particular 'string' in a file and remove the entire line where the occurrence of the string is found. I want it to work across with a collection of files. Can you help?
A:  It is possible to use grep for this: grep -v string file will output all lines that do not contain the string. But sed is a more suitable tool for batch editing.
sed --in-place '/some string/d' myfile
will delete all lines containing 'some string' To process a collection of files, you need to use a for loop (or find) because sed 's --in-place option only works on single files. One of these commands will do it:
for f in *.txt; do sed --in-place '/some string/d'
"$f"; done
find -name '*.txt' -exec sed --in-place=.bak '/some
string/d' "{}" ';'
Adding =.bak in the latter example makes sed save a backup of the original file before modifying it.

Saturday, April 5, 2014

VIM: Insert a string at the beginning of each line

This replaces the beginning of each line with "//":
:%s!^!//!
This replaces the beginning of each selected line (use visual mode to select) with "//":
:'<,'>s!^!//!
Refer:
http://stackoverflow.com/questions/253380/how-do-i-insert-text-at-beginning-of-a-multi-line-selection-in-vi-vim

Tuesday, April 1, 2014

setup Rsyslog and Mongodb on Centos 6.3

I did some modify and correct some errors from following  links.

The reference links:
1)http://loganalyzer.adiscon.com/articles/using-mongodb-with-rsyslog-and-loganalyzer
2http://wiki.rsyslog.com/index.php/HOWTO:_install_rsyslog_%2B_mongodb_%2B_loganalyzer_in_RHEL_6.2
3)http://wiki.rsyslog.com/index.php/Rsyslog_v6_configuration_example


//make sure that you install the EPEL source.
http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F



Install Apache + PHP:
----------------------
$yum install httpd php
$chkconfig httpd on
$service httpd start


Install Adiscon Loganalyzer:
-----------------------------
$yum install php-bcmath php-gd
Download, install and configure Adiscon Loganalyzer as documented in the INSTALL file to "/var/www/html". You can find the INSTALL file in the loganalyzer sources.
// cp all the folders and files from "/src" to "/var/www/html"


Install MongoDB:
----------------
$yum install mongodb mongodb-server php-pecl-mongo
$chkconfig mongod on
$service mongod start

Install the follow three packages with order: libestr -> libee -> liblognorm.
The reason why we need to build them from source is that we need to compile the Rsyslog by ourself.

Install libee, libestr, liblognorm:
------------------------------------
$yum install gcc make pkgconfig
Download, compile and install sources with:
$./configure --libdir=/usr/lib64/ --includedir=/usr/include --prefix=/usr
$make
$make install

Install libmongo-clientInstall libmongo-client:
------------------------------
$yum install git automake autoconf libtool glib2-devel
$git clone git://github.com/algernon/libmongo-client.git
$cd libmongo-client
$./autogen.sh
$./configure --libdir=/usr/lib64/ --includedir=/usr/include --prefix=/usr
$make
$make install
you may need following packages:
yum install json-c-devel libuuid libuuid-devel 

Install rsyslog:

yum install rsyslog-mongodb


manage Latex package manually on ubuntu

1. ubuntu doesn't support Latex automatic package system. they suggest you to manage package manually.
http://tex.stackexchange.com/questions/73116/fresh-install-texlive-2012-ubuntu-12-04-tlmgr-nowhere-to-be-found

2) here is the instruction for Manual management.
Installing packages manually
If a package you desire is not in Ubuntu's repositories, you may look on CTAN's web site or TeX Catalogue Online to see if they have the package. If they do, download the archive containing the files. In this example, we'll install example package foo, contained in foo.tar.gz.

Once foo.tar.gz has finished downloading, we unzip it somewhere in our home directory:


tar xvf foo.tar.gz
This expands to folder foo/. We cd into foo/ and see foo.ins. We now run LaTeX on the file:


latex foo.ins
This will generate foo.sty. We now have to copy this file into the correct location. This can be done in two ways. After these, you can use your new package in your LaTeX document by inserting \usepackage{foo} in the preamble.

User install

We will copy this into our personal texmf tree. The advantages of this solution are that if we migrate our files to a new computer, we will remember to take our texmf tree with us, resulting in keeping the same packages we had. The disadvantages are that if multiple users want to use the same packages, the tree will have to be copied to each user's home folder.

We'll first create the necessary directory structure:


cd ~
mkdir -p texmf/tex/latex/foo
Notice that the final directory created is labeled foo. It is a good idea to name directories after the packages they contain. The -p attribute to mkdir tells it to create all the necessary directories, since they don't exist. Now, using either the terminal, or the file manager, copy foo.sty into the directory labeled foo.

Now, we must make LaTeX recognize the new package:


texhash ~/texmf
System install

We will copy the foo to the LaTeX system tree. The advantages are that every user on the computer can access these files. The disadvantages are, that the method uses superuser privileges, and in a possible reformat/reinstall you have to repeat the procedure.

First, go to the folder your foo is located. The following commands will create a new directory for your files and copy it to the new folder:


sudo mkdir /usr/share/texmf/tex/latex/foo
sudo cp foo.sty /usr/share/texmf/tex/latex/foo
Then update the LaTeX package cache:


sudo texhash