Zhi-Jun's Blog

December 4, 2012

issues found when using emacs and how to fix

Filed under: emacs — Jack @ 09:36
Tags: , ,

  1. Desp: After upgrade emacs from ver 21.x to ver 24.2, when use C-X C-F to open folder/files, it report “Symbol’s function definition is void: make-local-hook”

    Solution: previous installed “ido.el” not compatible with current version of emacs, upgrade newest “ido” plugin from below link:
    http://bazaar.launchpad.net/~vcs-imports/emacs/trunk/annotate/head%3A/lisp/ido.el”

  1. TBD

eamcs tips

Filed under: emacs — Jack @ 09:23
Tags:

  • debug emacs errors: M-X toggle-debug-on-error
  • change minibuffer foreground/background color: (set-face-foreground ‘minibuffer-prompt “white” ), or use M-X: set-face-background<RTN> minibuffer-prompt<RTN> white to change online.
  • Several useful comint mode commands
    M-p, cycle backwards in input history
    M-n, cycle forwards
    M-r, Isearch input regexp backwords
    C-c C-o, delete last of process output
  • Evaluate lisp function within emacs, copy function into yank, then run with “C-x C-e”, for example force recompile whole directory: (byte-recompile-directory “.” 0)
  • Describe variable: C-h v
    • use emacs with mysql
      use SQLi mode:
      view long row of data: toggle-truncate-lines
      same sql commands into history file

        (defun my-sql-save-history-hook ()
          (let ((lval 'sql-input-ring-file-name)
                (rval 'sql-product))
            (if (symbol-value rval)
                (let ((filename 
                       (concat "~/.emacs.d/sql/"
                               (symbol-name (symbol-value rval))
                               "-history.sql")))
                  (set (make-local-variable lval) filename))
              (error
               (format "SQL history will not be saved because %s is nil"
                       (symbol-name rval))))))
        (add-hook 'sql-interactive-mode-hook 'my-sql-save-history-hook)

      then after you use sql mode to do query, use “C-C C-C” to make buffer save into file.

  • more powerful mini-buffer operation: icicles setup
    1. download zip from https://github.com/emacsmirror/icicles
    2. Configure init file as: (add-to-list ‘load-path “/path/icicles-master”)
    (require ‘icicles)
    3. turn on/off icy mode by: M-X icy-mode
  • TBD

Reference:

GNU emacs tips: http://www.gnu.org/software/emacs/emacs-faq.html#Matching-parentheses
emacs key shortcuts: http://ergoemacs.org/emacs/keyboard_shortcuts.html

November 2, 2012

Linux IO redirect

Filed under: linux — Jack @ 11:37

n>&m     means redirect FD n to the same places as FD m. Eg, 2>&1 means send STDERR to the same place that STDOUT is going to.

 

foo 2>&1 |tee /dev/tty >>outfile
foo >outfile1 2>&1 >outfile2
foo >file 2>&1          # Sends both stdout and stderr to file.

 

Good article:

http://mywiki.wooledge.org/BashFAQ/055

October 12, 2012

python tips: how to connect sql server through odbc in RHEL redhat linux

Filed under: c++,DB,linux,python — Jack @ 03:04
Tags:

Recently I need build a version of python to run logic  to connect remote sql server.

To enable this features in python, we need install below packages:

1. Microsoft SQL Server ODBC Driver V1.0 for Linux.   http://www.microsoft.com/en-us/download/details.aspx?id=28160

2. unixodbc

We have to setup odbc ini to make it works:

// set up odbcinst.ini, located in /etc/odbcinst.ini
//[SQL Server Native Client 11.0]
//Description=Microsoft SQL Server ODBC Driver V1.0 for Linux
//Driver=/opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1790.0
//Threading=1
//UsageCount=1

// setup odbc.ini
//[test1]
//Driver = SQL Server Native Client 11.0
//Description = Microsoft SQL Server ODBC Driver V1.0 for Linux
//SERVER = 11.11.1.161
//Database = vpdsqldev
//user = VPD
//port = 3306

To test if it works, we can use below commands:

sqlcmd -S11.11.1.11 -ddb_name -Uuser_name  -Q “select * from xxx”

You can also write c logic to connect by ODBC:

#include <sqlext.h>
#include <sql.h>
retcode = SQLConnect(hdbc, (SQLCHAR*) “dsn_name”, SQL_NTS, (SQLCHAR*) “username”, 3, (SQLCHAR*) “password”, 7);

Build with below :

// cc -m64 -g -I/usr/include -L/usr/lib64 -lstdc++ -lodbc -oxx xx.c

 

3. pyodbc.   http://code.google.com/p/pyodbc/
download package
run: python setup.py build install   // it is based on which python version you want to build on, change the first line in setup.py and python interpretor as well.

For example: there is customized version of python in :/opt/Python3/bin/python3

a), change the first ilne : #!/opt/Python3/bin/python3
b).  call :  /opt/Python3/bin/python3 setup.py build install
It is easy to install above process.

The reason my process is little complex is because my customized python shell is build with 32-bits

But mysql sql sver ODBCC driver for linux only have 64 bits version.

So I have to migrate my shell to 64 bits.

July 26, 2012

How to change guest resolution dynamically under virtual box

Filed under: linux — Jack @ 18:05

By default, Installed OS by default only have fixed guest resolution.

You need to install “guest additions” to enable dynamical resolution.

There are manual in virtual website:

http://www.virtualbox.org/manual/ch09.html#guestxorgsetup

http://www.virtualbox.org/manual/ch03.html#settings-display

 

 

July 18, 2012

How to mount an ISO file as CD-ROM

Filed under: linux — Jack @ 21:54

mount -t iso9660 -o ro,loop=/dev/loop0 /tmp/test.iso/media/cdrom/

June 6, 2012

RPM -e get error “specifies multiple packages”

Filed under: linux — Jack @ 09:38
Tags:

When I tried to erase RPM package when command “rpm -e xxx-1.4.0-1″

Error like:

error: “xxx-1.4.0-1″ specifies multiple packages

 

Use “rpm -q xxx-1.4.0-1″

We will get:

xxx-1.4.0-1
xxx-1.4.0-1

Instead, use
: pm -q –queryformat “%{name}.%{arch}\n” xxx-1.4.0-1

Try to create a file to make erase success

1. create new file with “ ~/.rpmmacros”

2. file content like:

%_query_all_fmt %%{name}-%%{version}-%%{release}.%%{arch}
3. Use “rpm -q xxx-1.4.0-1″

xxx-1.4.0-1.i386
xxx-1.4.0-1.x86_64

4. Right now, erase should work.

March 21, 2012

“autojump”, a quick way jumpping to a folder which instead of “cd”

Filed under: linux,shell — Jack @ 10:53
Tags: ,

There is one good tool “autojump”, which can help us quick jump to folders which you accessed before by key several keywords.

I think it’s behavior like:

1. when you access some folder, the tool will stored it in its repository.

2. After some-while, if user want to access again, user can only key in some keywords

3. then “autojump” will help user to search “repository” and help user complete the possible folder name.

Commands in “autojump”

1. “jumpstat”, list stored folder names in its repository.

2. if user want to jump one folder like “/home/demo/project/joelt/autojump/testing/redhat_demo/”

simple click:    j redhat

And click “TAB” in keyboard, then “autojump” will help user complete the whole folder.

 

Installation:

1. get latest package from : http://github.com/joelthelion/autojump/downloads

2. extract the package

3. change to root user

4. chmod +x install.sh

5. run install.sh

6. done

Prerequisite:

Key modules of “autojump” were implemented by “python”.

So please make sure python(version >= 2.7) was installed in your system.

 

Reference:

https://github.com/joelthelion/autojump/wiki

 

September 28, 2011

Symbol link issue when eploy php code under linux

Filed under: web — Jack @ 11:33
Tags:

When develop web application under linux, we always want to save “svn local copy” to our specific folder which isn’t inside in default “/var/www/html”.

The first idea we have is using “symbol link” to create linkage between “/var/www/html/web_app” and “/home/demouser/web_dev/web_app/”.

Unfortunately we always get “403 Forbidden” from Web browser.

If you suffer same issue above, you can refer to below steps to fix it.

1. check apache log files:
a. “/var/log/httpd/access_log”
b. “/var/log/httpd/error_log”, will report an error line like below:
“[error] [client xx.xx.xx.xx] Symbolic link not allowed or link target not accessible: /var/www/html/test”
2. check apache configure file:
“/etc/httpd/conf/httpd.conf”
to guarantee you set correct “Directory” attribute:

Options FollowSymLinks
AllowOverride None

3. Then check the folder you source code located, such as “/home/demouser/web_dev/web_app/” by:
nami -m /home/demouser/web_dev/web_app/

drwxr-xr-x /
drwxr-xr-x home
drwx------ demouser
drwxrwxr-x web_dev
drwxrwxrwx web_app

4. You can find there is no “x” execution permission for “demouser”, so just assign “-x” by:
chmod +x /home/demouser

5. Try again, the issue fixed.

Enjoy~

July 17, 2011

Add windows fonts to Redhat Linux

Filed under: linux — Jack @ 16:57
Tags:

My workstation was installed with RHEL 3.0 for many years.
Because of several reasons, I still keep this old version of linux.

But I feel more and more uncomfortable with the default default fonts in linux, especially during programming.

There are several fonts which is very fit for programmer. Look below articles:

http://www.iplaysoft.com/top10-programming-fonts.html

http://hivelogic.com/articles/top-10-programming-fonts/

http://www.levien.com/type/myfonts/inconsolata.html

beautiful fonts with ttf format:
Inconsolata:

http://code.google.com/p/googlefontdirectory/source/browse/inconsolata/Inconsolata.ttf?r=829b7e77062a1a06dfc90c29f0f413e2a1de44fe

Consolas:

http://code.google.com/p/isoblox/source/browse/art/consolas.ttf?r=72

Want to install this fonts to your linux?
Very easy.
Run below command as root:

fc-cache -fv

This command will scan all font directories and build fonts cache.
Just copy specific ttf files to one of the scan folders, such as /usr/share/fonts/…
Run above command again.

Then new fonts can be added in your system successfully.

Next Page »

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.