Posted on 25-01-2013
Filed Under (Technology) by bigbang

I use Putty to edit code romotely today. Because for some reason I can’t download or upload the files by WinSCP or something else, I can only do the coding using Emacs under Putty. It is really a bad experience using Emacs under Putty, and I don’t know why Emacs M-v keybinding doesn’t work under Putty. It is also really bad that I can’t use my own Emacs config file. I think there should be the same situation under secureCTR. It seems using Emacs Tramp is the best choice.

1. Install Putty

There is nothing to discuss about Putty installation, just do it.

2. Add Putty Installation Path to Windows System PATH

Make sure you add Putty installation path to Windows system PATH:

C:\Program Files\PuTTY

By doing it, we can let Emacs file plink.exe file.

3. Add Tramp code in Emacs Config File

Just put following elisp code into .emacs file:

(require 'tramp)
(setq tramp-auto-save-directory "c:\\tmp")
(setq tramp-default-method "plink")

4. Use Tramp to Edit Remote File

Now, we can use M-x find-file or C-x C-f to open remote file. When Emacs prompts the open info, just input the URL pattern of following:

/usr@machine:/path/to/file

For example, if you want to explore ~/main.c on remote host, you can open it with path:

/water@192.168.1.20:/home/water/main.c

Some machines use different port to provide SSH service, and in this situation we can use following URL to open file or folder:

/test@host#2222:/tmp

, which means using # to add specific port. Just write down the SSH port behind # to enable the connection.

When you are editing the remote file or folder, all the thing is the same as editing locally.

5. Tips

Although Emacs Tramp is very convinent for editing remote Linux host, it is still a better choice if you can download files and edit them locally. By this way, you can use Emacs, use more tools ( for example, Visual Studio, WinMerge, etc.) to coding, merging, copying. There is nothing happier than done the work quickly!

(0) Comments    Read More   
Posted on 25-01-2013
Filed Under (Emacs) by bigbang

If we don’t want Muse to escape * symbol which means export * directly, we can use = to do it.

For example,

=*word=*

will be exported as

=word=

Actually, = is short for <code></code> expression, and <code></code> is also very convinent to escape big block text.

(0) Comments    Read More   
Posted on 23-01-2013
Filed Under (Technology) by bigbang

I am using log4cxx in a normal way, which provides a property file for log4cxx. Here we can find some references1, 2 about it.

But if I want to set log4cxx properties in my C++ code without using property file, what should I do? Here is the code example from log4xxx Wiki:

#include <log4cxx/logger.h>
#include <log4cxx/helpers/pool.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/fileappender.h>
#include <log4cxx/simplelayout.h>

int main() {
    log4cxx::FileAppender * fileAppender = new log4cxx::FileAppender( log4cxx::LayoutPtr(new log4cxx::SimpleLayout()),
                                                                      "logfile", false);

    log4cxx::helpers::Pool p;
    fileAppender->activateOptions(p);

    log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(fileAppender));
    log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
    log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("logger");

    LOG4CXX_INFO(logger,"Created FileAppender appender");

    return 0;
}

The above code is only used for recording logs into log file. If we want to direct logs to console as well as writing to file, we need to add log4cxx::ConsoleAppender class into log4cxx::BasicConfigurator. Here is the sample code:

#include <log4cxx/logger.h>
#include <log4cxx/helpers/pool.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/fileappender.h>
#include <log4cxx/simplelayout.h>
#include "log4cxx/consoleappender.h"

LoggerPtr logger;

int main() {
    log4cxx::FileAppender * fileAppender = new log4cxx::FileAppender(log4cxx::LayoutPtr(new log4cxx::SimpleLayout()), L"logfile", false);

    log4cxx::ConsoleAppender * consoleAppender = new log4cxx::ConsoleAppender(log4cxx::LayoutPtr(new log4cxx::SimpleLayout()));

    log4cxx::helpers::Pool p;
    fileAppender->activateOptions(p);

    log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(fileAppender));
    log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(consoleAppender));
    log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
    log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("logger");

    LOG4CXX_INFO(logger,"Created FileAppender appender");

    return 0;
}

By the above code, the log will be redirected to file and console at the same time without a config file.

(0) Comments    Read More